Skip to content

Commit

Permalink
feat: Chip component redesign
Browse files Browse the repository at this point in the history
refactor: added selected state

refactor: added IconButton

refactor: styles refactoring

refactor: added tests

refactor: added new SCSS variables
  • Loading branch information
PKulkoRaccoonGang committed Oct 16, 2023
1 parent 98f7822 commit 9fa3921
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 132 deletions.
18 changes: 18 additions & 0 deletions src/Chip/Chip.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,23 @@ describe('<Chip />', () => {
await userEvent.type(iconAfter, '{enter}');
expect(func).toHaveBeenCalled();
});
it('onIconBeforeClick is triggered', async () => {
const func = jest.fn();
render(
<TestChip iconBefore={Close} onIconBeforeClick={func} />,
);
const iconBefore = screen.getByTestId('icon-before');
await userEvent.click(iconBefore);
expect(func).toHaveBeenCalled();
});
it('onIconBeforeKeyDown is triggered', async () => {
const func = jest.fn();
render(
<TestChip iconBefore={Close} onIconBeforeClick={func} />,
);
const iconBefore = screen.getByTestId('icon-before');
await userEvent.type(iconBefore, '{enter}');
expect(func).toHaveBeenCalled();
});
});
});
115 changes: 90 additions & 25 deletions src/Chip/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,99 @@ notes: |
## Basic Usage

```jsx live
<div>
<Chip>New</Chip>
<Chip disabled>New</Chip>
<Chip variant="dark">New</Chip>
</div>
<Stack
gap={2}
direction="horizontal"
>
<Chip>New</Chip>
<Chip disabled>New</Chip>
</Stack>
```

## With Icon Before and After
### Basic Usage

```jsx live
<div>
<Chip iconBefore={Person}>New</Chip>
<Chip
variant="dark"
iconBefore={Person}
iconAfter={Close}
onIconAfterClick={() => console.log('Remove Chip')}
>
New
</Chip>
<Chip
variant="dark"
iconBefore={Person}
iconAfter={Close}
onIconAfterClick={() => console.log('Remove Chip')}
disabled
>
New
</Chip>
</div>
<Stack
gap={2}
direction="horizontal"
>
<Chip iconBefore={Person}>New</Chip>
<Chip
iconBefore={Person}
iconAfter={Close}
onIconAfterClick={() => console.log('onIconAfterClick')}
>
New 1
</Chip>
<Chip
iconBefore={Person}
iconAfter={Close}
onIconBeforeClick={() => console.log('Remove Chip')}
>
New
</Chip>
<Chip
iconBefore={Person}
iconAfter={Close}
onIconBeforeClick={() => console.log('onIconBeforeClick')}
onIconAfterClick={() => console.log('onIconAfterClick')}
>
New
</Chip>
<Chip
iconBefore={Person}
iconAfter={Close}
onIconAfterClick={() => console.log('onIconAfterClick')}
disabled
>
New
</Chip>
</Stack>
```

### Inverse Pallete

```jsx live
<Stack
className="bg-dark-700 p-4"
gap={2}
direction="horizontal"
>
<Chip variant="dark" iconBefore={Person}>New</Chip>
<Chip
variant="dark"
iconBefore={Person}
iconAfter={Close}
onIconAfterClick={() => console.log('onIconAfterClick')}
>
New 1
</Chip>
<Chip
variant="dark"
iconBefore={Person}
iconAfter={Close}
onIconBeforeClick={() => console.log('Remove Chip')}
>
New
</Chip>
<Chip
variant="dark"
iconBefore={Person}
iconAfter={Close}
onIconBeforeClick={() => console.log('onIconBeforeClick')}
onIconAfterClick={() => console.log('onIconAfterClick')}
>
New
</Chip>
<Chip
variant="dark"
iconBefore={Person}
iconAfter={Close}
onIconAfterClick={() => console.log('onIconAfterClick')}
disabled
>
New
</Chip>
</Stack>
```
22 changes: 16 additions & 6 deletions src/Chip/__snapshots__/Chip.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
exports[`<Chip /> snapshots renders with props iconAfter 1`] = `
<div
className="pgn__chip pgn__chip-light"
onClick={[Function]}
onKeyPress={[Function]}
role="button"
tabIndex={0}
>
<div
className="pgn__chip__label p-after"
Expand All @@ -11,9 +15,6 @@ exports[`<Chip /> snapshots renders with props iconAfter 1`] = `
</div>
<div
className="pgn__chip__icon-after"
data-testid="icon-after"
role="button"
tabIndex={0}
>
<span
className="pgn__icon"
Expand Down Expand Up @@ -41,6 +42,10 @@ exports[`<Chip /> snapshots renders with props iconAfter 1`] = `
exports[`<Chip /> snapshots renders with props iconBefore 1`] = `
<div
className="pgn__chip pgn__chip-light"
onClick={[Function]}
onKeyPress={[Function]}
role="button"
tabIndex={0}
>
<div
className="pgn__chip__icon-before"
Expand Down Expand Up @@ -76,6 +81,10 @@ exports[`<Chip /> snapshots renders with props iconBefore 1`] = `
exports[`<Chip /> snapshots renders with props iconBefore and iconAfter 1`] = `
<div
className="pgn__chip pgn__chip-light"
onClick={[Function]}
onKeyPress={[Function]}
role="button"
tabIndex={0}
>
<div
className="pgn__chip__icon-before"
Expand Down Expand Up @@ -107,9 +116,6 @@ exports[`<Chip /> snapshots renders with props iconBefore and iconAfter 1`] = `
</div>
<div
className="pgn__chip__icon-after"
data-testid="icon-after"
role="button"
tabIndex={0}
>
<span
className="pgn__icon"
Expand Down Expand Up @@ -137,6 +143,10 @@ exports[`<Chip /> snapshots renders with props iconBefore and iconAfter 1`] = `
exports[`<Chip /> snapshots renders without props 1`] = `
<div
className="pgn__chip pgn__chip-light"
onClick={[Function]}
onKeyPress={[Function]}
role="button"
tabIndex={0}
>
<div
className="pgn__chip__label"
Expand Down
48 changes: 29 additions & 19 deletions src/Chip/_variables.scss
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
$chip-padding-x: .5rem !default;
$chip-padding-y: .125rem !default;
$chip-padding-to-icon: 3px !default;
$chip-icon-padding: .25rem !default;
$chip-margin: .125rem !default;
$chip-border-radius: .25rem !default;
$chip-disable-opacity: .3 !default;
$chip-icon-size: 1.25rem !default;

$chip-theme-variants: (
"light": (
"background": $light-500,
"color": $black,
),
"dark": (
"background": $dark-200,
"color": $white,
)
) !default;
$chip-padding-x: .5rem !default;
$chip-padding-y: 1px !default;
$chip-icon-margin: .25rem !default;
$chip-margin: .125rem !default;
$chip-border-radius: .375rem !default;
$chip-disable-opacity: .3 !default;
$chip-icon-size: 1.5rem !default;
$chip-label-color: $primary-700 !default;
$chip-border-color: $light-800 !default;
$chip-light-bg-color: $white !default;
$chip-light-outline-color: $chip-label-color !default;
$chip-light-selected-outline-distance: 3px !default;
$chip-light-selected-focus-border-color: $dark-500 !default;
$chip-light-hover-bg: $dark-500 !default;
$chip-light-hover-border-color: $chip-light-hover-bg !default;
$chip-light-hover-label-color: $chip-light-bg-color !default;
$chip-light-hover-icon-color: $chip-light-hover-label-color !default;
$chip-light-focus-outline-distance: .313rem !default;
$chip-dark-bg: $primary-300 !default;
$chip-dark-outline-color: $white !default;
$chip-dark-selected-outline-distance: 3px !default;
$chip-dark-selected-focus-border-color: $chip-dark-outline-color !default;
$chip-dark-label-color: $chip-dark-outline-color !default;
$chip-dark-hover-bg: $white !default;
$chip-dark-hover-border-color: $chip-dark-hover-bg !default;
$chip-dark-hover-label-color: $primary-500 !default;
$chip-dark-hover-icon-color: $chip-dark-hover-label-color !default;
$chip-dark-focus-outline-distance: .313rem !default;
$chip-dark-icon-border-color: transparent !default;
Loading

0 comments on commit 9fa3921

Please sign in to comment.