-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
131 additions
and
3 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
31 changes: 31 additions & 0 deletions
31
docs/src/demos/components/TextField/textfield-group.demo.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 { useState } from 'react'; | ||
import { Stack, TextField, FieldBaseGroup, Radio } from '@marigold/components'; | ||
|
||
export const GroupTextField = () => { | ||
const [value, setValue] = useState<string>(''); | ||
const error = value.length > 0 && !/^\d+$/.test(value); | ||
|
||
return ( | ||
<FieldBaseGroup labelWidth="20%"> | ||
<Stack space="small"> | ||
<TextField label="Name" /> | ||
<TextField | ||
label="Promo Code" | ||
description="You'll find your promo code on the back of your ticket." | ||
errorMessage="Your promo code is not valid! Please review your input." | ||
value={value} | ||
onChange={setValue} | ||
error={error} | ||
inputMode="numeric" | ||
pattern="[0-9]*" | ||
/> | ||
<Radio.Group label="Choose"> | ||
<Radio value="1">One</Radio> | ||
<Radio value="2">Two</Radio> | ||
<Radio value="3">Three</Radio> | ||
<Radio value="4">Four</Radio> | ||
</Radio.Group> | ||
</Stack> | ||
</FieldBaseGroup> | ||
); | ||
}; |
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,57 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { FieldBase } from './FieldBase'; | ||
import { FieldBaseGroup } from './FieldBaseGroup'; | ||
|
||
test('renders FieldBaseGroup', () => { | ||
render( | ||
<FieldBaseGroup> | ||
<FieldBase label="Label" description="Description"> | ||
<input type="text" /> | ||
</FieldBase> | ||
</FieldBaseGroup> | ||
); | ||
|
||
const group = screen.getByText('Label').parentElement; | ||
expect(group).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders FieldBaseGroup by default without label width', () => { | ||
render( | ||
<FieldBaseGroup> | ||
<FieldBase label="Label" description="Description"> | ||
<input type="text" /> | ||
</FieldBase> | ||
</FieldBaseGroup> | ||
); | ||
|
||
const label = screen.getByText('Label'); | ||
expect(label).not.toHaveAttribute('labelWidth'); | ||
}); | ||
|
||
test('renders FieldBaseGroup with label width', () => { | ||
render( | ||
<FieldBaseGroup labelWidth="20px"> | ||
<FieldBase label="Label" description="Description"> | ||
<input type="text" /> | ||
</FieldBase> | ||
</FieldBaseGroup> | ||
); | ||
|
||
const label = screen.getByText('Label'); | ||
expect(label).toHaveStyle('width: 20px'); | ||
}); | ||
|
||
test('renders FieldBaseGroups children', () => { | ||
render( | ||
<FieldBaseGroup labelWidth="20px"> | ||
<FieldBase label="Label" description="Description"> | ||
<input type="text" /> | ||
</FieldBase> | ||
</FieldBaseGroup> | ||
); | ||
|
||
expect(screen.getByText('Label')).toBeInTheDocument(); | ||
expect(screen.getByText('Description')).toBeInTheDocument(); | ||
}); |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './FieldBase'; | ||
export * from './FieldBaseGroup'; |
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,7 @@ | ||
import type { Theme } from '@marigold/components'; | ||
|
||
export const Field: Theme['components']['Field'] = { | ||
base: { | ||
flexDirection: 'column', | ||
}, | ||
}; |
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,7 @@ | ||
import type { Theme } from '@marigold/components'; | ||
|
||
export const Field: Theme['components']['Field'] = { | ||
base: { | ||
flexDirection: 'column', | ||
}, | ||
}; |
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