-
Notifications
You must be signed in to change notification settings - Fork 16
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
Build out the <FormField />
and <TextInput />
components, and add other features in preparation for new v2 pages
#1653
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7590b1a
Start building out Input component
jessepinho c614bf8
Move the ActionType type to its own file
jessepinho 67f6850
Update text.secondary color
jessepinho eb8f9f6
Add a bunch more props and styling
jessepinho de803ce
Tweak the theme
jessepinho f4ee9c7
Create DisabledContext and corresponding hook
jessepinho 273e182
Build out <Card /> with stacks of sections
jessepinho e843829
Remove unnecessary markup/styling
jessepinho e0574d5
Use the new useDisabled hook in SegmentedControl
jessepinho 7229f07
Restructure components
jessepinho 7ade979
Fix colors
jessepinho 3afaee9
Add some docs
jessepinho ca90ad4
Add more docs to <Card />
jessepinho 6f9f614
Changeset
jessepinho 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
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,5 @@ | ||
--- | ||
'@repo/ui': minor | ||
--- | ||
|
||
Create <Card />'s subcomponents; create <FormField /> and <TextInput />; add some features re: disabled fields |
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 |
---|---|---|
|
@@ -30,16 +30,14 @@ export const DashboardLayout = () => { | |
|
||
<Grid tablet={8} desktop={6} xl={4}> | ||
<Card title={CARD_TITLE_BY_PATH[v2PathPrefix(pagePath)]}> | ||
<div className='flex flex-col gap-4'> | ||
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 wrapper is no longer needed, since |
||
<Tabs | ||
value={v2PathPrefix(pagePath)} | ||
onChange={value => navigate(value)} | ||
options={TABS_OPTIONS} | ||
actionType='accent' | ||
/> | ||
|
||
<Outlet /> | ||
</div> | ||
<Tabs | ||
value={v2PathPrefix(pagePath)} | ||
onChange={value => navigate(value)} | ||
options={TABS_OPTIONS} | ||
actionType='accent' | ||
/> | ||
|
||
<Outlet /> | ||
</Card> | ||
</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
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
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 |
---|---|---|
|
@@ -71,7 +71,7 @@ const Color = <T extends Exclude<TColor, 'action' | 'other' | 'base'>>({ color } | |
<Grid mobile={6} tablet={10}> | ||
<Variants> | ||
{color === 'text' | ||
? (['primary', 'secondary', 'disabled', 'special'] as const).map(variant => ( | ||
? (['primary', 'secondary', 'muted', 'special'] as const).map(variant => ( | ||
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. (due to the updated theme values) |
||
<Variant key={variant} $color={color} $colorVariant={variant}> | ||
<Text technical>{variant}</Text> | ||
</Variant> | ||
|
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,59 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { FormField } from '.'; | ||
import { TextInput } from '../TextInput'; | ||
import { useState } from 'react'; | ||
import { SegmentedControl } from '../SegmentedControl'; | ||
|
||
const meta: Meta<typeof FormField> = { | ||
component: FormField, | ||
tags: ['autodocs', '!dev'], | ||
argTypes: { | ||
children: { control: false }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof FormField>; | ||
|
||
export const TextInputExample: Story = { | ||
args: { | ||
label: "Recipient's address", | ||
helperText: 'The recipient can find their address via the Receive tab.', | ||
disabled: false, | ||
}, | ||
|
||
render: function Render(props) { | ||
const [recipient, setRecipient] = useState(''); | ||
|
||
return ( | ||
<FormField {...props}> | ||
<TextInput value={recipient} onChange={setRecipient} placeholder='penumbra1abc123...' /> | ||
</FormField> | ||
); | ||
}, | ||
}; | ||
|
||
export const SegmentedControlExample: Story = { | ||
args: { | ||
label: 'Fee Tier', | ||
disabled: false, | ||
}, | ||
|
||
render: function Render(props) { | ||
const [feeTier, setFeeTier] = useState('low'); | ||
|
||
return ( | ||
<FormField {...props}> | ||
<SegmentedControl | ||
value={feeTier} | ||
options={[ | ||
{ label: 'Low', value: 'low' }, | ||
{ label: 'Medium', value: 'medium' }, | ||
{ label: 'High', value: 'high' }, | ||
]} | ||
onChange={setFeeTier} | ||
/> | ||
</FormField> | ||
); | ||
}, | ||
}; |
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 @@ | ||
import styled from 'styled-components'; | ||
import { small, strong } from '../utils/typography'; | ||
import { ReactNode } from 'react'; | ||
import { DisabledContext } from '../utils/DisabledContext'; | ||
|
||
const Root = styled.label` | ||
display: flex; | ||
flex-direction: column; | ||
gap: ${props => props.theme.spacing(2)}; | ||
position: relative; | ||
`; | ||
|
||
const HelperText = styled.div<{ $disabled: boolean }>` | ||
color: ${props => | ||
props.$disabled ? props.theme.color.text.muted : props.theme.color.text.secondary}; | ||
|
||
${small} | ||
`; | ||
|
||
const LabelText = styled.div<{ $disabled: boolean }>` | ||
${strong} | ||
|
||
color: ${props => | ||
props.$disabled ? props.theme.color.text.muted : props.theme.color.text.primary}; | ||
`; | ||
|
||
export interface FormFieldProps { | ||
label: string; | ||
/** | ||
* Setting this to `true` will render the `<FormField />` as disabled, and | ||
* will also disable whatever input component you pass as children (if that | ||
* component uses the `useDisabled()` hook). | ||
* | ||
* Thus, you can simply set `disabled` on the `<FormField />`, and don't need | ||
* to _also_ set it on the child input component. | ||
*/ | ||
disabled?: boolean; | ||
helperText?: string; | ||
/** | ||
* The form control to render for this field, whether a `<TextInput />`, | ||
* `<SegmentedControl />`, etc. | ||
*/ | ||
children: ReactNode; | ||
} | ||
|
||
/** | ||
* A wrapper around a field in a form. Provides a standardized presentation for | ||
* any inputs, such as `<TextInput />`, `<SegmentedControl />`, etc. | ||
* | ||
* ```tsx | ||
* <FormField | ||
* label="Field label" | ||
* helperText="This is the helper text." | ||
* disabled={disabled} | ||
* > | ||
* <TextInput value={value} onChange={onChange} /> | ||
* </FormField> | ||
* ``` | ||
* | ||
* Note that, in the example above, you can simply pass the `disabled` prop to | ||
* `<FormField />`, and it will take care of disabling its child input component | ||
* via context (assuming the child input component uses the `useDisabled()` | ||
* hook). | ||
*/ | ||
export const FormField = ({ label, disabled = false, helperText, children }: FormFieldProps) => ( | ||
<Root> | ||
<LabelText $disabled={disabled}>{label}</LabelText> | ||
|
||
<DisabledContext.Provider value={disabled}>{children}</DisabledContext.Provider> | ||
|
||
{helperText && <HelperText $disabled={disabled}>{helperText}</HelperText>} | ||
</Root> | ||
); |
Oops, something went wrong.
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.
The
div
was never needed, since it only had one child