-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
UI: Create new form elements in the new Core UI (Input, TextArea, Select) #23469
Changes from 3 commits
312c23f
f56ded7
f9b9e9a
be6ad7b
42ba728
4d2bcad
d3dad50
4a21186
a164fd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Input } from './Input'; | ||
|
||
const meta: Meta<typeof Input> = { | ||
title: 'Input', | ||
component: Input, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Input>; | ||
|
||
export const Base: Story = { | ||
args: { | ||
placeholder: 'Hello World', | ||
}, | ||
}; | ||
|
||
export const Filled: Story = { | ||
args: { | ||
...Base.args, | ||
value: 'Hello World', | ||
}, | ||
}; | ||
|
||
export const Disabled: Story = { | ||
args: { | ||
...Base.args, | ||
disabled: true, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { forwardRef } from 'react'; | ||
import { styled } from '@storybook/theming'; | ||
|
||
interface InputProps { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding PropTypes for better type checking and to make the code more self-documenting. [medium] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. euh ... no. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a lie, it's actually more!
|
||
disabled?: boolean; | ||
placeholder?: string; | ||
value?: string; | ||
} | ||
|
||
export const Input = forwardRef<HTMLInputElement, InputProps>(({ ...props }, ref) => { | ||
return <StyledInput ref={ref} {...props} />; | ||
}); | ||
Comment on lines
+10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
|
||
Input.displayName = 'Input'; | ||
|
||
const StyledInput = styled.input(({ theme }) => ({ | ||
// resets | ||
appearance: 'none', | ||
border: '0 none', | ||
display: 'block', | ||
margin: ' 0', | ||
position: 'relative', | ||
|
||
// styles | ||
width: '100%', | ||
height: '32px', | ||
transition: 'box-shadow 200ms ease-out, opacity 200ms ease-out', | ||
color: theme.input.color, | ||
background: theme.input.background, | ||
boxShadow: `${theme.input.border} 0 0 0 1px inset`, | ||
borderRadius: theme.input.borderRadius, | ||
fontSize: theme.typography.size.s2 - 1, | ||
padding: '6px 10px', | ||
boxSizing: 'border-box', | ||
lineHeight: '20px', | ||
|
||
'&:focus': { | ||
boxShadow: `${theme.color.secondary} 0 0 0 1px inset`, | ||
outline: 'none', | ||
}, | ||
|
||
'&[disabled]': { | ||
cursor: 'not-allowed', | ||
opacity: 0.5, | ||
}, | ||
|
||
'&:-webkit-autofill': { | ||
WebkitBoxShadow: `0 0 0 3em ${theme.color.lightest} inset`, | ||
}, | ||
|
||
'&::placeholder': { | ||
color: theme.textMutedColor, | ||
opacity: 1, | ||
}, | ||
})); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Textarea } from './Textarea'; | ||
|
||
const meta: Meta<typeof Textarea> = { | ||
title: 'Textarea', | ||
component: Textarea, | ||
tags: ['autodocs'], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof Textarea>; | ||
|
||
export const Base: Story = { | ||
args: { | ||
placeholder: 'Hello World', | ||
}, | ||
}; | ||
|
||
export const Filled: Story = { | ||
args: { | ||
...Base.args, | ||
value: | ||
'Self ocean ultimate reason faith virtues evil eternal-return moral strong superiority. Society will christian god holiest evil virtues ultimate salvation aversion victorious strong eternal-return. Ascetic pious hope selfish battle pinnacle revaluation passion ocean passion chaos reason intentions. Hope hatred pious superiority ascetic chaos ultimate mountains ideal. Superiority good abstract hatred holiest passion ultimate evil inexpedient joy. Salvation war salvation ideal decieve good law ascetic hatred transvaluation horror good. Zarathustra aversion pious truth burying evil inexpedient spirit virtues virtues hope salvation transvaluation. Enlightenment chaos ascetic salvation god holiest play marvelous oneself ocean. Enlightenment faithful dead truth insofar fearful madness love.Inexpedient war hatred superiority disgust justice superiority. Chaos justice contradict christian decieve god. Revaluation suicide hope enlightenment decrepit truth hatred insofar gains sexuality merciful ocean revaluation depths. Revaluation ocean superiority endless of evil horror. Ultimate salvation joy good good endless will horror aversion superiority depths. Evil hatred ideal pious joy reason.', | ||
}, | ||
}; | ||
|
||
export const Disabled: Story = { | ||
args: { | ||
...Base.args, | ||
disabled: true, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { forwardRef } from 'react'; | ||
import { styled } from '@storybook/theming'; | ||
import TextareaAutoResize from 'react-textarea-autosize'; | ||
|
||
interface TextareaProps { | ||
ndelangen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
disabled?: boolean; | ||
placeholder?: string; | ||
value?: string; | ||
} | ||
|
||
export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(({ ...props }, ref) => { | ||
return <StyledTextarea ref={ref} {...props} />; | ||
}); | ||
|
||
Textarea.displayName = 'Textarea'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this needed? Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it's a forwardRef with an arrow function inside. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is needed to make sure React devtools function correctly. This triggers an error otherwise. |
||
|
||
const StyledTextarea = styled(TextareaAutoResize)(({ theme }) => ({ | ||
// resets | ||
appearance: 'none', | ||
border: '0 none', | ||
margin: ' 0', | ||
position: 'relative', | ||
|
||
// styles | ||
display: 'flex', | ||
alignItems: 'center', | ||
width: '100%', | ||
height: '32px', | ||
transition: 'box-shadow 200ms ease-out, opacity 200ms ease-out', | ||
color: theme.input.color, | ||
background: theme.input.background, | ||
boxShadow: `${theme.input.border} 0 0 0 1px inset`, | ||
borderRadius: theme.input.borderRadius, | ||
fontSize: theme.typography.size.s2 - 1, | ||
padding: '6px 10px', | ||
boxSizing: 'border-box', | ||
minHeight: 32, | ||
lineHeight: '20px', | ||
|
||
'&:focus': { | ||
boxShadow: `${theme.color.secondary} 0 0 0 1px inset`, | ||
outline: 'none', | ||
}, | ||
|
||
'&[disabled]': { | ||
cursor: 'not-allowed', | ||
opacity: 0.5, | ||
}, | ||
|
||
'&:-webkit-autofill': { | ||
WebkitBoxShadow: `0 0 0 3em ${theme.color.lightest} inset`, | ||
}, | ||
|
||
'&::placeholder': { | ||
color: theme.textMutedColor, | ||
opacity: 1, | ||
}, | ||
})); |
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.
Consider adding more diverse storybook examples to cover different use cases and edge cases. [medium]
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.
Interesting one. I could do that.