-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: input field * fix: typo * test: add customClass unit test * feature: add input to docs * fix: remove touch state from input Co-authored-by: Maomao <maomao.zha@gmail.com>
- Loading branch information
Showing
45 changed files
with
1,117 additions
and
717 deletions.
There are no files selected for viewing
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
12 changes: 12 additions & 0 deletions
12
packages/components/src/components/input-error/__snapshots__/input-error.spec.ts.snap
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,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Input Error should match snapshot 1`] = ` | ||
<t-input-error> | ||
<mock:shadow-root> | ||
<div class="input-error"> | ||
<slot></slot> | ||
</div> | ||
</mock:shadow-root> | ||
Error | ||
</t-input-error> | ||
`; |
13 changes: 13 additions & 0 deletions
13
packages/components/src/components/input-error/input-error.css
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,13 @@ | ||
/** | ||
* @prop --input-error-font-size: Font size of the input-error | ||
* @prop --input-error-font-family: Font family of the input-error | ||
* @prop --input-error-padding-top: Padding top of the input-error | ||
* @prop --input-error-color: Color of the input-error | ||
*/ | ||
|
||
.input-error { | ||
font-size: var(--input-error-font-size, 0.8rem); | ||
font-family: var(--input-error-font-family, unset); | ||
padding-top: var(--input-error-padding-top, 0.5rem); | ||
color: var(--input-error-color, lightcoral); | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/components/src/components/input-error/input-error.e2e.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,10 @@ | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
|
||
describe('t-input-error', () => { | ||
it('renders', async () => { | ||
const page = await newE2EPage(); | ||
await page.setContent('<t-input-error/>'); | ||
const element = await page.find('t-input-error'); | ||
expect(element).toHaveClass('hydrated'); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
packages/components/src/components/input-error/input-error.spec.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,31 @@ | ||
import { newSpecPage } from '@stencil/core/testing'; | ||
import { InputError } from './input-error'; | ||
|
||
describe('Input Error', () => { | ||
let element; | ||
beforeEach(async () => { | ||
element = new InputError(); | ||
}); | ||
|
||
it('should match snapshot', async () => { | ||
const page = await newSpecPage({ | ||
components: [InputError], | ||
html: `<t-input-error>Error</t-input-error>`, | ||
}); | ||
expect(page.root).toMatchSnapshot(); | ||
}); | ||
|
||
it('should handle a custom css class', () => { | ||
element.customClass = 'custom'; | ||
expect(element.getCssClassMap()).toContain('custom'); | ||
}); | ||
|
||
it('should handle theme css class', () => { | ||
element.theme = 'default'; | ||
expect(element.getCssClassMap()).toContain('input-error--theme-default'); | ||
}); | ||
|
||
it('should have a default css class', () => { | ||
expect(element.getCssClassMap()).toContain('input-error'); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
packages/components/src/components/input-error/input-error.tsx
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,31 @@ | ||
import { Component, Prop, h } from '@stencil/core'; | ||
import { CssClassMap } from '../../utils/utils'; | ||
import classNames from 'classnames'; | ||
|
||
@Component({ | ||
tag: 't-input-error', | ||
styleUrl: 'input-error.css', | ||
shadow: true, | ||
}) | ||
export class InputError { | ||
/** (optional) Input text class */ | ||
@Prop() public customClass?: string = ''; | ||
/** (optional) Input text theme */ | ||
@Prop() public theme?: string = ''; | ||
|
||
public render() { | ||
return ( | ||
<div class={this.getCssClassMap()}> | ||
<slot /> | ||
</div> | ||
); | ||
} | ||
|
||
private getCssClassMap(): CssClassMap { | ||
return classNames( | ||
'input-error', | ||
this.customClass && this.customClass, | ||
this.theme && `input-error--theme-${this.theme}` | ||
); | ||
} | ||
} |
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,28 @@ | ||
# t-input-text | ||
|
||
|
||
|
||
<!-- Auto Generated Below --> | ||
|
||
|
||
## Properties | ||
|
||
| Property | Attribute | Description | Type | Default | | ||
| ------------- | -------------- | --------------------------- | -------- | ------- | | ||
| `customClass` | `custom-class` | (optional) Input text class | `string` | `''` | | ||
| `theme` | `theme` | (optional) Input text theme | `string` | `''` | | ||
|
||
|
||
## CSS Custom Properties | ||
|
||
| Name | Description | | ||
| --------------------------- | ------------------------------ | | ||
| `--input-error-color` | Color of the input-error | | ||
| `--input-error-font-family` | Font family of the input-error | | ||
| `--input-error-font-size` | Font size of the input-error | | ||
| `--input-error-padding-top` | Padding top of the input-error | | ||
|
||
|
||
---------------------------------------------- | ||
|
||
*Built with [StencilJS](https://stenciljs.com/)* |
12 changes: 12 additions & 0 deletions
12
packages/components/src/components/input-group/__snapshots__/input-group.spec.ts.snap
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,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Input Group should match snapshot 1`] = ` | ||
<t-input-group> | ||
<mock:shadow-root> | ||
<div class="input-group"> | ||
<slot></slot> | ||
</div> | ||
</mock:shadow-root> | ||
Label | ||
</t-input-group> | ||
`; |
11 changes: 11 additions & 0 deletions
11
packages/components/src/components/input-group/input-group.css
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,11 @@ | ||
:host { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.input-group { | ||
display: flex; | ||
flex-direction: inherit; | ||
width: 100%; | ||
margin-bottom: 1rem; | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/components/src/components/input-group/input-group.e2e.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,10 @@ | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
|
||
describe('t-input-group', () => { | ||
it('renders', async () => { | ||
const page = await newE2EPage(); | ||
await page.setContent('<t-input-group/>'); | ||
const element = await page.find('t-input-group'); | ||
expect(element).toHaveClass('hydrated'); | ||
}); | ||
}); |
Oops, something went wrong.