-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: input directive #569
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0672e43
refactor(theme): rename form control variables
yggg 863d663
feat(nbInput): add input directive
yggg 5bb269d
docs(nbInput): document api, add examples
yggg e07425c
feat(nbInput): remove disabled attribute
yggg 84aa82b
style(nbInput): remove unused import
yggg 975ac6d
style(theme): remove unused variables
yggg aeb234c
refactor(nbInput): remove input prefixes
yggg 2cb53da
feat(nbInput): add tests
yggg 76f2357
feat(nbInput): add fullwidth option
yggg f0202dd
feat(nbInput): add fullWidth option tests
yggg 10f1f82
docs(nbInput): put inputs on cards
yggg 2ab8a12
docs(nbInput): add placeholders
yggg acd10b5
refactor(nbInput): chage size to fieldSize
yggg 03fd71a
Merge branch 'master' into feature/inputs
yggg c0e42b8
Merge branch 'master' into feature/inputs
yggg 38e6af0
fix(nbInput): use proper field name
yggg f628a4c
feat(input): add input icon to docs
yggg baf7cca
Merge branch 'master' into feature/inputs
yggg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
@mixin input-colors() { | ||
&.input-info { | ||
border-color: nb-theme(form-control-info-border-color); | ||
} | ||
&.input-success { | ||
border-color: nb-theme(form-control-success-border-color); | ||
} | ||
&.input-warning { | ||
border-color: nb-theme(form-control-warning-border-color); | ||
} | ||
&.input-danger { | ||
border-color: nb-theme(form-control-danger-border-color); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
@mixin input-shapes() { | ||
&.input-rectangle { | ||
border-radius: nb-theme(form-control-border-radius); | ||
} | ||
&.input-semi-round { | ||
border-radius: nb-theme(form-control-semi-round-border-radius); | ||
} | ||
&.input-round { | ||
border-radius: nb-theme(form-control-round-border-radius); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
@mixin input-sizes() { | ||
&.input-sm { | ||
font-size: nb-theme(form-control-font-size-sm); | ||
padding: nb-theme(form-control-padding-sm); | ||
} | ||
&.input-md { | ||
font-size: nb-theme(form-control-font-size); | ||
padding: nb-theme(form-control-padding); | ||
} | ||
&.input-lg { | ||
font-size: nb-theme(form-control-font-size-lg); | ||
padding: nb-theme(form-control-padding-lg); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/framework/theme/components/input/_input.directive.theme.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
@import './input-colors'; | ||
@import './input-sizes'; | ||
@import './input-shapes'; | ||
|
||
@mixin nb-input-theme() { | ||
$border-width: nb-theme(form-control-border-width); | ||
$border-type: nb-theme(form-control-border-type); | ||
$border-color: nb-theme(form-control-border-color); | ||
|
||
[nbInput] { | ||
background-color: nb-theme(form-control-bg); | ||
border: $border-width $border-type $border-color; | ||
color: nb-theme(form-control-text-primary-color); | ||
|
||
&:focus { | ||
outline: none; | ||
background-color: nb-theme(form-control-focus-bg); | ||
border-color: nb-theme(form-control-selected-border-color); | ||
} | ||
|
||
&[disabled] { | ||
@include install-placeholder( | ||
rgba(nb-theme(form-control-placeholder-color), 0.5), | ||
nb-theme(form-control-placeholder-font-size) | ||
); | ||
} | ||
|
||
&.input-full-width { | ||
width: 100%; | ||
} | ||
|
||
@include input-colors(); | ||
@include input-sizes(); | ||
@include input-shapes(); | ||
|
||
@include install-placeholder( | ||
nb-theme(form-control-placeholder-color), | ||
nb-theme(form-control-placeholder-font-size) | ||
); | ||
} | ||
} |
167 changes: 167 additions & 0 deletions
167
src/framework/theme/components/input/input.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { Directive, Input, HostBinding } from '@angular/core'; | ||
import { convertToBoolProperty } from '../helpers'; | ||
|
||
/** | ||
* Basic input directive. | ||
* | ||
* ```html | ||
* <input nbInput></input> | ||
* ``` | ||
* | ||
* Default input size is `medium`: | ||
* @stacked-example(Showcase, input/input-showcase.component) | ||
* | ||
* Inputs are available in multiple colors using `status` property: | ||
* @stacked-example(Input Colors, input/input-colors.component) | ||
* | ||
* There are three input sizes: | ||
* | ||
* @stacked-example(Input Sizes, input/input-sizes.component) | ||
* | ||
* Inputs available in different shapes, which could be combined with the other properties: | ||
* @stacked-example(Input Shapes, input/input-shapes.component) | ||
* | ||
* `nbInput` could be applied to the following selectors - `input`, `textarea`: | ||
* @stacked-example(Input Elements, input/input-types.component) | ||
* | ||
* You can add `fullWidth` attribute to make element fill container: | ||
* @stacked-example(Full width inputs, input/input-full-width.component) | ||
* | ||
* @styles | ||
* | ||
* form-control-bg: | ||
* form-control-border-width: | ||
* form-control-border-type: | ||
* form-control-border-color: | ||
* form-control-text-primary-color: | ||
* form-control-focus-bg: | ||
* form-control-selected-border-color: | ||
* form-control-placeholder-font-size: | ||
* form-control-placeholder-color: | ||
* form-control-font-size: | ||
* form-control-padding: | ||
* form-control-font-size-sm: | ||
* form-control-padding-sm: | ||
* form-control-font-size-lg: | ||
* form-control-padding-lg: | ||
* form-control-border-radius: | ||
* form-control-semi-round-border-radius: | ||
* form-control-round-border-radius: | ||
* form-control-info-border-color: | ||
* form-control-success-border-color: | ||
* form-control-warning-border-color: | ||
* form-control-danger-border-color: | ||
*/ | ||
@Directive({ | ||
selector: 'input[nbInput],textarea[nbInput]', | ||
}) | ||
export class NbInputDirective { | ||
|
||
static readonly SIZE_SMALL = 'small'; | ||
static readonly SIZE_MEDIUM = 'medium'; | ||
static readonly SIZE_LARGE = 'large'; | ||
|
||
static readonly STATUS_INFO = 'info'; | ||
static readonly STATUS_SUCCESS = 'success'; | ||
static readonly STATUS_WARNING = 'warning'; | ||
static readonly STATUS_DANGER = 'danger'; | ||
|
||
static readonly SHAPE_RECTANGLE = 'rectangle'; | ||
static readonly SHAPE_SEMI_ROUND = 'semi-round'; | ||
static readonly SHAPE_ROUND = 'round'; | ||
|
||
size: string = NbInputDirective.SIZE_MEDIUM; | ||
|
||
/** | ||
* Field size, available sizes: | ||
* `small`, `medium`, `large` | ||
* @param {string} val | ||
*/ | ||
@Input('fieldSize') | ||
set setSize(value: string) { | ||
this.size = value; | ||
} | ||
|
||
/** | ||
* Field status (adds specific styles): | ||
* `info`, `success`, `warning`, `danger` | ||
* @param {string} val | ||
*/ | ||
@Input('status') | ||
status: string; | ||
|
||
/** | ||
* Field shapes: `rectangle`, `round`, `semi-round` | ||
* @param {string} val | ||
*/ | ||
@Input('shape') | ||
shape: string = NbInputDirective.SHAPE_RECTANGLE; | ||
|
||
/** | ||
* If set element will fill container | ||
* @param {string} | ||
*/ | ||
@Input('fullWidth') | ||
set setFullWidth(value) { | ||
this.fullWidth = convertToBoolProperty(value); | ||
} | ||
|
||
@HostBinding('class.input-full-width') | ||
fullWidth = false; | ||
|
||
@HostBinding('class.input-sm') | ||
get small() { | ||
return this.size === NbInputDirective.SIZE_SMALL; | ||
} | ||
|
||
@HostBinding('class.input-md') | ||
get medium() { | ||
return this.size === NbInputDirective.SIZE_MEDIUM; | ||
} | ||
|
||
@HostBinding('class.input-lg') | ||
get large() { | ||
return this.size === NbInputDirective.SIZE_LARGE; | ||
} | ||
|
||
@HostBinding('class.input-info') | ||
get info() { | ||
return this.status === NbInputDirective.STATUS_INFO; | ||
} | ||
|
||
@HostBinding('class.input-success') | ||
get success() { | ||
return this.status === NbInputDirective.STATUS_SUCCESS; | ||
} | ||
|
||
@HostBinding('class.input-warning') | ||
get warning() { | ||
return this.status === NbInputDirective.STATUS_WARNING; | ||
} | ||
|
||
@HostBinding('class.input-danger') | ||
get danger() { | ||
return this.status === NbInputDirective.STATUS_DANGER; | ||
} | ||
|
||
@HostBinding('class.input-rectangle') | ||
get rectangle() { | ||
return this.shape === NbInputDirective.SHAPE_RECTANGLE; | ||
} | ||
|
||
@HostBinding('class.input-semi-round') | ||
get semiRound() { | ||
return this.shape === NbInputDirective.SHAPE_SEMI_ROUND; | ||
} | ||
|
||
@HostBinding('class.input-round') | ||
get round() { | ||
return this.shape === NbInputDirective.SHAPE_ROUND; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @license | ||
* Copyright Akveo. All Rights Reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*/ | ||
|
||
import { NgModule } from '@angular/core'; | ||
import { NbSharedModule } from '../shared/shared.module'; | ||
import { NbInputDirective } from './input.directive'; | ||
|
||
const NB_INPUT_COMPONENTS = [ | ||
NbInputDirective, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [ NbSharedModule ], | ||
declarations: NB_INPUT_COMPONENTS, | ||
exports: NB_INPUT_COMPONENTS, | ||
}) | ||
export class NbInputModule {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add placeholders into examples