-
Notifications
You must be signed in to change notification settings - Fork 13
feat: form components #718
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9ef4c38
feat: form components
rohanchkrabrty 6f5b830
feat: update form
rohanchkrabrty bb9341a
Merge branch 'main' into feat-form-components
rohanchkrabrty e0d7c8d
fix: field style
rohanchkrabrty 8604557
chore: fix migration doc and tests
rohanchkrabrty 0fdc32e
fix: update doc
rohanchkrabrty 21cdecd
Update apps/www/src/content/docs/components/textarea/demo.ts
rohanchkrabrty 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 hidden or 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,32 @@ | ||
| 'use client'; | ||
|
|
||
| import { Field, Flex, InputField, TextArea } from '@raystack/apsara'; | ||
| import PlaygroundLayout from './playground-layout'; | ||
|
|
||
| export function FieldExamples() { | ||
| return ( | ||
| <PlaygroundLayout title='Field'> | ||
| <Flex gap='large' wrap='wrap'> | ||
| <Flex gap='large' direction='column' style={{ width: 300 }}> | ||
| <Field label='Name' required helperText='Enter your full name'> | ||
| <InputField placeholder='John Doe' /> | ||
| </Field> | ||
| <Field label='Email' error='Please enter a valid email'> | ||
| <InputField type='email' placeholder='Enter email' /> | ||
| </Field> | ||
| <Field label='Phone' optional> | ||
| <InputField placeholder='Enter phone' /> | ||
| </Field> | ||
| </Flex> | ||
| <Flex gap='large' direction='column' style={{ width: 300 }}> | ||
| <Field label='Bio' optional helperText='Tell us about yourself'> | ||
| <TextArea placeholder='Write something...' /> | ||
| </Field> | ||
| <Field label='Disabled' disabled> | ||
| <InputField placeholder='Cannot edit' /> | ||
| </Field> | ||
| </Flex> | ||
| </Flex> | ||
| </PlaygroundLayout> | ||
| ); | ||
| } |
This file contains hidden or 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,26 @@ | ||
| 'use client'; | ||
|
|
||
| import { Field, Fieldset, Flex, InputField } from '@raystack/apsara'; | ||
| import PlaygroundLayout from './playground-layout'; | ||
|
|
||
| export function FieldsetExamples() { | ||
| return ( | ||
| <PlaygroundLayout title='Fieldset'> | ||
| <Flex gap='large' direction='column' style={{ maxWidth: 400 }}> | ||
| <Fieldset legend='Contact Details'> | ||
| <Field label='Phone' required> | ||
| <InputField type='tel' placeholder='+1 (555) 000-0000' /> | ||
| </Field> | ||
| <Field label='Address' optional> | ||
| <InputField placeholder='123 Main St' /> | ||
| </Field> | ||
| </Fieldset> | ||
| <Fieldset legend='Disabled Section' disabled> | ||
| <Field label='Read Only'> | ||
| <InputField placeholder='Cannot edit' /> | ||
| </Field> | ||
| </Fieldset> | ||
| </Flex> | ||
| </PlaygroundLayout> | ||
| ); | ||
| } |
This file contains hidden or 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,41 @@ | ||
| 'use client'; | ||
|
|
||
| import { | ||
| Button, | ||
| Field, | ||
| Fieldset, | ||
| Form, | ||
| InputField, | ||
| TextArea | ||
| } from '@raystack/apsara'; | ||
| import PlaygroundLayout from './playground-layout'; | ||
|
|
||
| export function FormExamples() { | ||
| return ( | ||
| <PlaygroundLayout title='Form'> | ||
| <Form | ||
| onSubmit={e => { | ||
| e.preventDefault(); | ||
| alert('Form submitted!'); | ||
| }} | ||
| style={{ maxWidth: 400 }} | ||
| > | ||
| <Fieldset legend='Personal Information'> | ||
| <Field label='First Name' required> | ||
| <InputField placeholder='John' /> | ||
| </Field> | ||
| <Field label='Last Name' required> | ||
| <InputField placeholder='Doe' /> | ||
| </Field> | ||
| </Fieldset> | ||
| <Field label='Email' required helperText="We'll send a confirmation"> | ||
| <InputField type='email' placeholder='john@example.com' /> | ||
| </Field> | ||
| <Field label='Message' optional> | ||
| <TextArea placeholder='Tell us more...' /> | ||
| </Field> | ||
| <Button type='submit'>Submit</Button> | ||
| </Form> | ||
| </PlaygroundLayout> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,103 @@ | ||
| 'use client'; | ||
|
|
||
| import { getPropsString } from '@/lib/utils'; | ||
|
|
||
| export const getCode = (props: any) => { | ||
| const { label, helperText, error, required, optional, ...rest } = props; | ||
| const fieldProps: Record<string, unknown> = {}; | ||
| if (label) fieldProps.label = label; | ||
| if (helperText) fieldProps.helperText = helperText; | ||
| if (error) fieldProps.error = error; | ||
| if (required) fieldProps.required = required; | ||
| if (optional) fieldProps.optional = optional; | ||
| return `<Field${getPropsString(fieldProps)}> | ||
| <InputField${getPropsString(rest)} placeholder="Enter text" /> | ||
| </Field>`; | ||
| }; | ||
|
|
||
| export const playground = { | ||
| type: 'playground', | ||
| controls: { | ||
| label: { type: 'text', initialValue: 'Email' }, | ||
| helperText: { type: 'text', initialValue: "We won't share your email" }, | ||
| error: { type: 'text', initialValue: '' }, | ||
| required: { type: 'checkbox', initialValue: false, defaultValue: false }, | ||
| optional: { type: 'checkbox', initialValue: false, defaultValue: false }, | ||
| disabled: { type: 'checkbox', initialValue: false, defaultValue: false } | ||
| }, | ||
| getCode | ||
| }; | ||
|
|
||
| export const simpleDemo = { | ||
| type: 'code', | ||
| code: `<Field label="Name" helperText="Enter your full name"> | ||
| <InputField placeholder="John Doe" /> | ||
| </Field>` | ||
| }; | ||
|
|
||
| export const errorDemo = { | ||
| type: 'code', | ||
| code: `<Field label="Email" error="Please enter a valid email address"> | ||
| <InputField placeholder="Enter email" /> | ||
| </Field>` | ||
| }; | ||
|
|
||
| export const helperTextDemo = { | ||
| type: 'code', | ||
| code: `<Field label="Password" helperText="Must be at least 8 characters"> | ||
| <InputField type="password" placeholder="Enter password" /> | ||
| </Field>` | ||
| }; | ||
|
|
||
| export const requiredDemo = { | ||
| type: 'code', | ||
| code: `<Field label="Username" required> | ||
| <InputField placeholder="Enter username" /> | ||
| </Field>` | ||
| }; | ||
|
|
||
| export const optionalDemo = { | ||
| type: 'code', | ||
| code: `<Field label="Phone Number" optional helperText="We may use this for verification"> | ||
| <InputField placeholder="Enter phone number" /> | ||
| </Field>` | ||
| }; | ||
|
|
||
| export const subComponentDemo = { | ||
| type: 'code', | ||
| code: `<Field name="email"> | ||
| <Field.Label>Email</Field.Label> | ||
| <Field.Control required type="email" placeholder="Enter email" /> | ||
| <Field.Error match="valueMissing">Email is required</Field.Error> | ||
| <Field.Error match="typeMismatch">Please enter a valid email</Field.Error> | ||
| <Field.Description>We'll send a verification link</Field.Description> | ||
| </Field>` | ||
| }; | ||
|
|
||
| export const withInputFieldDemo = { | ||
| type: 'code', | ||
| code: `<Field label="Full Name" required helperText="As it appears on your ID"> | ||
| <InputField placeholder="John Doe" /> | ||
| </Field>` | ||
| }; | ||
|
|
||
| export const withTextAreaDemo = { | ||
| type: 'code', | ||
| code: `<Field label="Bio" optional helperText="Tell us about yourself"> | ||
| <TextArea placeholder="Write something..." /> | ||
| </Field>` | ||
| }; | ||
|
|
||
| export const withSelectDemo = { | ||
| type: 'code', | ||
| code: `<Field label="Country" required> | ||
| <Select> | ||
| <Select.Trigger /> | ||
| <Select.Content> | ||
| <Select.Item value="us">United States</Select.Item> | ||
| <Select.Item value="uk">United Kingdom</Select.Item> | ||
| <Select.Item value="ca">Canada</Select.Item> | ||
| </Select.Content> | ||
| </Select> | ||
| </Field>` | ||
| }; |
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.
Uh oh!
There was an error while loading. Please reload this page.