Skip to content

Commit

Permalink
update docs and add test ids to buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanjamal committed May 30, 2023
1 parent 5b46f66 commit ae47e77
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
12 changes: 7 additions & 5 deletions packages/segmented-buttons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Demo build](https://github.com/hey-car/heycar-uikit/actions/workflows/main.yml/badge.svg)](https://github.com/hey-car/heycar-uikit/actions/workflows/main.yml)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

Review ratings are a 0 to 10 rating with a dial, used in connection with reviews.
Segmented buttons help people select options, switch views, or sort elements

## Installation

Expand All @@ -18,11 +18,13 @@ npm install @heycar-uikit/segmented-buttons
## Usage

```tsx
import SegmentedButtons from '@heycar-uikit/segmented-buttons';
// TSX/JSX file
import SegmentedButtons from '@heycar-uikit/core/segmented-buttons';
```

function App() {
return <SegmentedButtons />;
}
```css
// CSS file
@import '@heycar-uikit/core/segmented-buttons/esm/SegmentedButtons.css';
```

## Documentation and sandbox
Expand Down
1 change: 1 addition & 0 deletions packages/segmented-buttons/src/SegmentedButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const SegmentedButtons = React.forwardRef<
<button
aria-checked={isActive}
aria-label={btn.label}
data-test-id={btn.dataTestId}
disabled={btn.isDisabled}
key={btn.label}
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ const TWO_BTNS: Buttons = [
value: 'lft',
isDisabled: false,
icon: undefined,
dataTestId: 'btn-1',
},
{
label: 'Right',
value: 'rht',
isDisabled: false,
icon: undefined,
dataTestId: 'btn-2',
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Gallery } from '@heycar-uikit/icons';

import SegmentedButtons from '../SegmentedButtons';

import { BTN_DATA, modifyBtns } from './SegmentedButtons.mocks';
import { BTN_DATA, modifyBtns, TWO_BTNS } from './SegmentedButtons.mocks';

const dataTestId = 'test-id';

Expand All @@ -30,6 +30,19 @@ describe('SegmentedButtons', () => {
expect(getByTestId(dataTestId).tagName).toBe('DIV');
});

it('should set `data-test-id` attribute on buttons', () => {
const { getByTestId } = render(
<SegmentedButtons
buttons={TWO_BTNS}
dataTestId={dataTestId}
onChange={onChange}
/>,
);

expect(getByTestId('btn-1').tagName).toBe('BUTTON');
expect(getByTestId('btn-2').tagName).toBe('BUTTON');
});

it('should set className', () => {
const className = 'test-class';
const { container } = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ Object {
<button
aria-checked="false"
aria-label="Left"
data-test-id="btn-1"
role="radio"
>
Left
</button>
<button
aria-checked="false"
aria-label="Right"
data-test-id="btn-2"
role="radio"
>
Right
Expand All @@ -36,13 +38,15 @@ Object {
<button
aria-checked="false"
aria-label="Left"
data-test-id="btn-1"
role="radio"
>
Left
</button>
<button
aria-checked="false"
aria-label="Right"
data-test-id="btn-2"
role="radio"
>
Right
Expand Down
13 changes: 10 additions & 3 deletions packages/segmented-buttons/src/docs/Component.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,19 @@ export const SegmentedButtonsTemplate = ({ ...props }) => {
name="SegmentedButtons"
version={version}
stage={1}
design="https://www.figma.com/file/rrvkvQEoVTOHa7MzyKSaoz/Design-system?node-id=11667-213068&t=cdniDk8YJcZcnIwr-0"
design="https://www.figma.com/file/rrvkvQEoVTOHa7MzyKSaoz/Design-system?type=design&node-id=2073-48212&t=5DXQ5Fj9xmmbEVBw-0"
/>

Review ratings are a 0 to 10 rating with a dial, used in connection with reviews.
Segmented buttons help people select options, switch views, or sort elements

```tsx
import SegmentedButtons from '@heycar-uikit/segmented-buttons';
// TSX/JSX file
import SegmentedButtons from '@heycar-uikit/core/segmented-buttons';
```

```css
// CSS file
@import '@heycar-uikit/core/segmented-buttons/esm/SegmentedButtons.css';
```

<!-- Description -->
Expand All @@ -104,3 +110,4 @@ import SegmentedButtons from '@heycar-uikit/segmented-buttons';
{ label: 'Changelog', component: <Changelog /> },
]}
/>
```

0 comments on commit ae47e77

Please sign in to comment.