-
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.
- Loading branch information
Showing
16 changed files
with
906 additions
and
10 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,55 @@ | ||
import { Description, Meta, Props } from 'docsComponents'; | ||
|
||
<Meta title="RadioButton" /> | ||
|
||
# RadioButton | ||
|
||
<Description of="RadioButton" /> | ||
|
||
## Props | ||
|
||
<Props of="RadioButton" /> | ||
|
||
## Examples | ||
|
||
### Basic | ||
|
||
A basic usage of RadioButton. | ||
|
||
```js live | ||
<RadioButton>Hello World!</RadioButton> | ||
``` | ||
|
||
### Disabled | ||
|
||
Radio Buttons can be disabled. | ||
|
||
```js live | ||
<RadioButton disabled>Disabled</RadioButton> | ||
``` | ||
|
||
### Size | ||
|
||
Radio Buttons can have different sizes. | ||
|
||
```js live | ||
<Row gutter={1}> | ||
<Col span={24}> | ||
<RadioButton size="sm">Small</RadioButton> | ||
</Col> | ||
<Col span={24}> | ||
<RadioButton size="md">Medium</RadioButton> | ||
</Col> | ||
<Col span={24}> | ||
<RadioButton size="lg">Large</RadioButton> | ||
</Col> | ||
</Row> | ||
``` | ||
|
||
### Error | ||
|
||
A Radio Button can indicate it has an error. | ||
|
||
```js live | ||
<RadioButton hasError>Text indicating error</RadioButton> | ||
``` |
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,128 @@ | ||
import { Description, Meta, Props } from 'docsComponents'; | ||
|
||
<Meta title="RadioGroup" /> | ||
|
||
# RadioGroup | ||
|
||
<Description of="RadioGroup" /> | ||
|
||
## Props | ||
|
||
<Props of="RadioGroup" /> | ||
|
||
## Examples | ||
|
||
### Basic | ||
|
||
A basic usage of RadioGroup. | ||
|
||
```js live withRender | ||
const options = [ | ||
{ label: 'Javascript', value: 'js' }, | ||
{ label: 'Typescript', value: 'ts' }, | ||
{ label: 'Coffescript', value: 'coffee' } | ||
]; | ||
|
||
render(<RadioGroup name="language-1" options={options} />); | ||
``` | ||
|
||
### Controlled | ||
|
||
RadioGroup is designed to be used as a controlled input. | ||
|
||
```js live withRender | ||
const options = [ | ||
{ label: 'Javascript', value: 'js' }, | ||
{ label: 'Typescript', value: 'ts' }, | ||
{ label: 'Coffescript', value: 'coffee' } | ||
]; | ||
|
||
const Controlled = (props) => { | ||
const [value, setValue] = useState('ts'); | ||
return ( | ||
<> | ||
<RadioGroup | ||
{...props} | ||
value={value} | ||
onChange={(ev) => setValue(ev.target.value)} | ||
/> | ||
<Block> | ||
Value: <i>{value}</i> | ||
</Block> | ||
</> | ||
); | ||
}; | ||
|
||
render(<Controlled name="language-2" options={options} />); | ||
``` | ||
|
||
### Inline | ||
|
||
A RadioGroup can be Inline | ||
|
||
```js live withRender | ||
const options = [ | ||
{ label: 'Javascript', value: 'js' }, | ||
{ label: 'Typescript', value: 'ts' }, | ||
{ label: 'Coffescript', value: 'coffee' } | ||
]; | ||
|
||
render(<RadioGroup inline name="language" options={options} />); | ||
``` | ||
|
||
### Disabled | ||
|
||
Options inside a RadioGroup can be disabled. | ||
|
||
```js live withRender | ||
const options = [ | ||
{ label: 'Javascript', value: 'js' }, | ||
{ label: 'Typescript', value: 'ts' }, | ||
{ label: 'Coffescript', value: 'coffee', disabled: true } | ||
]; | ||
|
||
render(<RadioGroup name="language-3" options={options} />); | ||
``` | ||
|
||
### Size | ||
|
||
RadioGroups can have different sizes. | ||
|
||
```js live withRender | ||
const options = [ | ||
{ label: 'Javascript', value: 'js' }, | ||
{ label: 'Typescript', value: 'ts' }, | ||
{ label: 'Coffescript', value: 'coffee' } | ||
]; | ||
|
||
render( | ||
<Row gutter={1}> | ||
<Col span={8}> | ||
<H4>Small</H4> | ||
<RadioGroup size="sm" name="language-4" options={options} /> | ||
</Col> | ||
<Col span={8}> | ||
<H4>Medium</H4> | ||
<RadioGroup size="md" name="language-5" options={options} /> | ||
</Col> | ||
<Col span={8}> | ||
<H4>Large</H4> | ||
<RadioGroup size="lg" name="language-6" options={options} /> | ||
</Col> | ||
</Row> | ||
); | ||
``` | ||
|
||
### Error | ||
|
||
Options inside a RadioGroup can indicate to have an error. | ||
|
||
```js live withRender | ||
const options = [ | ||
{ label: 'Javascript', value: 'js' }, | ||
{ label: 'Typescript', value: 'ts' }, | ||
{ label: 'Coffescript', value: 'coffee', hasError: true } | ||
]; | ||
|
||
render(<RadioGroup name="language-7" options={options} />); | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { render } from '@testing-library/react'; | ||
import React, { createRef } from 'react'; | ||
import { RadioButton } from './RadioButton'; | ||
|
||
describe('RadioButton', () => { | ||
it('renders an input radio element and sets child text', () => { | ||
render(<RadioButton>Hello world!</RadioButton>); | ||
const container = document.querySelector('.mvn--radio-button'); | ||
const input = document.querySelector('input'); | ||
expect(container).toBeInTheDocument(); | ||
expect(input).toBeInTheDocument(); | ||
expect(input).toHaveAttribute('type', 'radio'); | ||
expect(container).toHaveTextContent('Hello world!'); | ||
}); | ||
|
||
it('sets className', () => { | ||
render( | ||
<RadioButton className="radio-button-class">Hello world!</RadioButton> | ||
); | ||
const element = document.querySelector('.mvn--radio-button'); | ||
expect(element).toHaveClass('radio-button-class'); | ||
}); | ||
|
||
it('passes props', () => { | ||
render( | ||
<RadioButton id="RadioButtonId" data-test="radio-button-data"> | ||
Hello world! | ||
</RadioButton> | ||
); | ||
const element = document.querySelector('input'); | ||
expect(element).toHaveAttribute('id', 'RadioButtonId'); | ||
expect(element).toHaveAttribute('data-test', 'radio-button-data'); | ||
}); | ||
|
||
describe('disabled', () => { | ||
it('is not disabled by default', () => { | ||
render(<RadioButton />); | ||
const input = document.querySelector('input'); | ||
expect(input).not.toHaveAttribute('disabled'); | ||
}); | ||
|
||
it('sets disabled', () => { | ||
render(<RadioButton disabled />); | ||
const input = document.querySelector('input'); | ||
expect(input).toHaveAttribute('disabled'); | ||
}); | ||
}); | ||
|
||
describe('hasError', () => { | ||
it('has no error styling by default', () => { | ||
render(<RadioButton />); | ||
const container = document.querySelector('.mvn--radio-button'); | ||
expect(container).not.toHaveClass('has-error'); | ||
}); | ||
|
||
it('sets error styling', () => { | ||
render(<RadioButton hasError>Error Text</RadioButton>); | ||
const container = document.querySelector('.mvn--radio-button'); | ||
expect(container).toHaveClass('has-error'); | ||
}); | ||
}); | ||
|
||
describe('size', () => { | ||
it('is md by default', () => { | ||
render(<RadioButton />); | ||
const container = document.querySelector('.mvn--radio-button'); | ||
expect(container).toHaveClass('md'); | ||
expect(container).not.toHaveClass('sm'); | ||
expect(container).not.toHaveClass('lg'); | ||
}); | ||
|
||
it('sets sm', () => { | ||
render(<RadioButton size="sm" />); | ||
const container = document.querySelector('.mvn--radio-button'); | ||
expect(container).toHaveClass('sm'); | ||
}); | ||
|
||
it('sets lg', () => { | ||
render(<RadioButton size="lg" />); | ||
const container = document.querySelector('.mvn--radio-button'); | ||
expect(container).toHaveClass('lg'); | ||
}); | ||
}); | ||
|
||
describe('forwarding ref', () => { | ||
it('sets ref', () => { | ||
const ref = createRef<HTMLInputElement>(); | ||
render(<RadioButton ref={ref} />); | ||
const element = document.querySelector('input'); | ||
expect(ref.current).toBe(element); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.