-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from etchteam/feature/etch-384-input
Input component
- Loading branch information
Showing
8 changed files
with
215 additions
and
12 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
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
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,73 @@ | ||
diamond-input { | ||
--_background: var(--diamond-input-background); | ||
--_border-color: var(--diamond-input-border-color); | ||
|
||
background: var(--_background); | ||
border: 1px solid var(--_border-color); | ||
border-radius: var(--diamond-input-border-radius); | ||
color: var(--diamond-input-color); | ||
display: flex; | ||
overflow: hidden; | ||
position: relative; | ||
transition: | ||
border-color var(--diamond-transition), | ||
background-color var(--diamond-transition); | ||
|
||
&:hover, | ||
&:focus-within { | ||
--_border-color: var(--diamond-input-border-color-hover); | ||
} | ||
|
||
&:focus-within { | ||
--_background: var(--diamond-input-background-focus); | ||
} | ||
|
||
&[state='valid'] { | ||
--_border-color: var(--diamond-input-border-color-valid); | ||
} | ||
|
||
&[state='invalid'] { | ||
--_border-color: var(--diamond-input-border-color-invalid); | ||
} | ||
|
||
&:has([disabled]) { | ||
--_background: var(--diamond-input-background-disabled); | ||
cursor: not-allowed; | ||
opacity: 0.5; | ||
pointer-events: none; | ||
} | ||
|
||
input { | ||
appearance: none; | ||
background: none; | ||
border: 0 none; | ||
color: inherit; | ||
display: block; | ||
line-height: var(--diamond-input-line-height); | ||
min-height: var(--diamond-spacing-thumb); | ||
padding: var(--diamond-input-padding); | ||
width: 100%; | ||
|
||
&:focus { | ||
outline: none; | ||
} | ||
} | ||
|
||
svg { | ||
block-size: var(--diamond-input-icon-size); | ||
flex-shrink: 0; | ||
inline-size: var(--diamond-input-icon-size); | ||
} | ||
|
||
/* Prefix */ | ||
&:has(* + input) :first-child { | ||
margin-right: calc(var(--diamond-input-padding-horizontal) / 2 * -1); | ||
padding: 0 0 0 var(--diamond-input-padding-horizontal); | ||
} | ||
|
||
/* Suffix */ | ||
input + * { | ||
margin-left: calc(var(--diamond-input-padding-horizontal) / 2 * -1); | ||
padding: 0 var(--diamond-input-padding-horizontal) 0 0; | ||
} | ||
} |
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,97 @@ | ||
import { StoryObj } from '@storybook/web-components'; | ||
import { html } from 'lit'; | ||
|
||
import './Input'; | ||
import '../../composition/Grid/Grid'; | ||
import '../../composition/Grid/GridItem'; | ||
|
||
export default { | ||
component: 'diamond-input', | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: | ||
'Wraps an HTML input element to provide consistent styling and behavior.', | ||
}, | ||
}, | ||
}, | ||
argTypes: { | ||
state: { | ||
control: { | ||
type: 'select', | ||
}, | ||
options: ['valid', 'invalid'], | ||
}, | ||
}, | ||
}; | ||
|
||
export const Input: StoryObj = { | ||
render: (args) => html` | ||
<diamond-input state="${args.state}"> | ||
<input /> | ||
</diamond-input> | ||
`, | ||
}; | ||
|
||
export const InputStates: StoryObj = { | ||
render: () => html` | ||
<diamond-grid wrap="wrap"> | ||
<diamond-grid-item> | ||
<diamond-input state="valid"> | ||
<input value="valid" /> | ||
</diamond-input> | ||
</diamond-grid-item> | ||
<diamond-grid-item> | ||
<diamond-input state="invalid"> | ||
<input value="invalid" /> | ||
</diamond-input> | ||
</diamond-grid-item> | ||
<diamond-grid-item> | ||
<diamond-input> | ||
<input value="disabled" disabled /> | ||
</diamond-input> | ||
</diamond-grid-item> | ||
</diamond-grid> | ||
`, | ||
}; | ||
|
||
export const Affix: StoryObj = { | ||
render: () => html` | ||
<diamond-grid wrap="wrap"> | ||
<diamond-grid-item> | ||
<diamond-input> | ||
<svg | ||
viewBox="0 0 24 24" | ||
stroke="currentColor" | ||
fill="none" | ||
width="24" | ||
height="24" | ||
aria-label="Send mail" | ||
> | ||
<path | ||
d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" | ||
/> | ||
</svg> | ||
<input value="prefix" /> | ||
</diamond-input> | ||
</diamond-grid-item> | ||
<diamond-grid-item> | ||
<diamond-input> | ||
<input value="suffix" /> | ||
<svg | ||
viewBox="0 0 24 24" | ||
stroke="currentColor" | ||
fill="none" | ||
width="24" | ||
height="24" | ||
aria-label="Send mail" | ||
> | ||
<path | ||
d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" | ||
/> | ||
</svg> | ||
</diamond-input> | ||
</diamond-grid-item> | ||
</diamond-grid> | ||
`, | ||
}; |
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,19 @@ | ||
export {}; | ||
|
||
export interface InputAttributes { | ||
state?: 'valid' | 'invalid'; | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'diamond-input': InputAttributes; | ||
} | ||
} | ||
|
||
declare module 'react' { | ||
namespace JSX { | ||
interface IntrinsicElements { | ||
'diamond-input': InputAttributes & React.HTMLAttributes<HTMLElement>; | ||
} | ||
} | ||
} |
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