Skip to content

Commit

Permalink
creating Checkbox component
Browse files Browse the repository at this point in the history
  • Loading branch information
brenocastelo committed Dec 13, 2022
1 parent e16ac52 commit c1e86fc
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/docs/src/stories/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { StoryObj, Meta } from '@storybook/react';
import { Box, Checkbox, CheckboxProps, Text } from '@ignite-ui/react';
import { StoryFnReactReturnType } from '@storybook/react/dist/ts3.9/client/preview/types';

export default {
title: 'Form/Checkbox',
component: Checkbox,
args: {},
decorators: [
(Story: () => StoryFnReactReturnType) => {
return (
<Box
as="label"
css={{ display: 'flex', flexDirection: 'row', gap: '$2' }}
>
{Story()}
<Text size="sm">Accept terms of use</Text>
</Box>
);
},
],
} as Meta<CheckboxProps>;

export const Primary: StoryObj<CheckboxProps> = {};
1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"@radix-ui/react-avatar": "^1.0.1",
"@radix-ui/react-checkbox": "^1.0.1",
"@stitches/react": "^1.2.8",
"phosphor-react": "^1.4.1"
}
Expand Down
16 changes: 16 additions & 0 deletions packages/react/src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Check } from 'phosphor-react';
import { ComponentProps } from 'react';
import { CheckboxContainer, CheckboxIndicator } from './styles';

export function Checkbox() {
return (
<CheckboxContainer>
<CheckboxIndicator asChild>
<Check weight="bold" />
</CheckboxIndicator>
</CheckboxContainer>
);
}

export interface CheckboxProps
extends ComponentProps<typeof CheckboxContainer> {}
56 changes: 56 additions & 0 deletions packages/react/src/components/Checkbox/styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as Checkbox from '@radix-ui/react-checkbox';
import { styled, keyframes } from '../../styles';

export const CheckboxContainer = styled(Checkbox.Root, {
all: 'unset',
height: '$6',
width: '$6',
borderRadius: '$xs',
backgroundColor: '$gray900',
cursor: 'pointer',
overflow: 'hidden',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
border: '2px solid $gray900',

'&:focus': {
border: '2px solid $ignite300',
},

'&[data-state="checked"]': {
backgroundColor: '$ignite300',
},
});

const slidIn = keyframes({
from: {
transform: 'translateY(-100%)',
},
to: {
transform: 'translateY(0)',
},
});

const slidOut = keyframes({
from: {
transform: 'translateY(0)',
},
to: {
transform: 'translateY(-100%)',
},
});

export const CheckboxIndicator = styled(Checkbox.CheckboxIndicator, {
color: '$white',
height: '$4',
width: '$4',

'&[data-state="checked"]': {
animation: `${slidIn} 200ms ease-out`,
},

'&[data-state="unchecked"]': {
animation: `${slidOut} 200ms ease-out`,
},
});
1 change: 1 addition & 0 deletions packages/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './components/Avatar';
export * from './components/Button';
export * from './components/TextInput';
export * from './components/TextArea';
export * from './components/Checkbox';
54 changes: 54 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,13 @@
schema-utils "^3.0.0"
source-map "^0.7.3"

"@radix-ui/primitive@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@radix-ui/primitive/-/primitive-1.0.0.tgz#e1d8ef30b10ea10e69c76e896f608d9276352253"
integrity sha512-3e7rn8FDMin4CgeL7Z/49smCA3rFYY3Ha2rUQ7HRWFadS5iCRw08ZgVT1LaNTCNqgvrUiyczLflrVrF0SRQtNA==
dependencies:
"@babel/runtime" "^7.13.10"

"@radix-ui/react-avatar@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@radix-ui/react-avatar/-/react-avatar-1.0.1.tgz#d25ef10b56210039c152e45209dd41a1afdc192e"
Expand All @@ -1609,6 +1616,21 @@
"@radix-ui/react-use-callback-ref" "1.0.0"
"@radix-ui/react-use-layout-effect" "1.0.0"

"@radix-ui/react-checkbox@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@radix-ui/react-checkbox/-/react-checkbox-1.0.1.tgz#80cb38b1fd2cbe73f3ad0f4db8aebead0ab0617a"
integrity sha512-TisH0B8hWmYP3ONRduYCyN04rR9yLPIw/Rwyn1RoC1suSoGCa8Wn+YPdSSSarSszeIbcg3p2lBkDp2XXit4sZw==
dependencies:
"@babel/runtime" "^7.13.10"
"@radix-ui/primitive" "1.0.0"
"@radix-ui/react-compose-refs" "1.0.0"
"@radix-ui/react-context" "1.0.0"
"@radix-ui/react-presence" "1.0.0"
"@radix-ui/react-primitive" "1.0.1"
"@radix-ui/react-use-controllable-state" "1.0.0"
"@radix-ui/react-use-previous" "1.0.0"
"@radix-ui/react-use-size" "1.0.0"

"@radix-ui/react-compose-refs@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@radix-ui/react-compose-refs/-/react-compose-refs-1.0.0.tgz#37595b1f16ec7f228d698590e78eeed18ff218ae"
Expand All @@ -1623,6 +1645,15 @@
dependencies:
"@babel/runtime" "^7.13.10"

"@radix-ui/react-presence@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@radix-ui/react-presence/-/react-presence-1.0.0.tgz#814fe46df11f9a468808a6010e3f3ca7e0b2e84a"
integrity sha512-A+6XEvN01NfVWiKu38ybawfHsBjWum42MRPnEuqPsBZ4eV7e/7K321B5VgYMPv3Xx5An6o1/l9ZuDBgmcmWK3w==
dependencies:
"@babel/runtime" "^7.13.10"
"@radix-ui/react-compose-refs" "1.0.0"
"@radix-ui/react-use-layout-effect" "1.0.0"

"@radix-ui/react-primitive@1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@radix-ui/react-primitive/-/react-primitive-1.0.1.tgz#c1ebcce283dd2f02e4fbefdaa49d1cb13dbc990a"
Expand All @@ -1646,13 +1677,36 @@
dependencies:
"@babel/runtime" "^7.13.10"

"@radix-ui/react-use-controllable-state@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@radix-ui/react-use-controllable-state/-/react-use-controllable-state-1.0.0.tgz#a64deaafbbc52d5d407afaa22d493d687c538b7f"
integrity sha512-FohDoZvk3mEXh9AWAVyRTYR4Sq7/gavuofglmiXB2g1aKyboUD4YtgWxKj8O5n+Uak52gXQ4wKz5IFST4vtJHg==
dependencies:
"@babel/runtime" "^7.13.10"
"@radix-ui/react-use-callback-ref" "1.0.0"

"@radix-ui/react-use-layout-effect@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@radix-ui/react-use-layout-effect/-/react-use-layout-effect-1.0.0.tgz#2fc19e97223a81de64cd3ba1dc42ceffd82374dc"
integrity sha512-6Tpkq+R6LOlmQb1R5NNETLG0B4YP0wc+klfXafpUCj6JGyaUc8il7/kUZ7m59rGbXGczE9Bs+iz2qloqsZBduQ==
dependencies:
"@babel/runtime" "^7.13.10"

"@radix-ui/react-use-previous@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@radix-ui/react-use-previous/-/react-use-previous-1.0.0.tgz#e48a69c3a7d8078a967084038df66d0d181c56ac"
integrity sha512-RG2K8z/K7InnOKpq6YLDmT49HGjNmrK+fr82UCVKT2sW0GYfVnYp4wZWBooT/EYfQ5faA9uIjvsuMMhH61rheg==
dependencies:
"@babel/runtime" "^7.13.10"

"@radix-ui/react-use-size@1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@radix-ui/react-use-size/-/react-use-size-1.0.0.tgz#a0b455ac826749419f6354dc733e2ca465054771"
integrity sha512-imZ3aYcoYCKhhgNpkNDh/aTiU05qw9hX+HHI1QDBTyIlcFjgeFlKKySNGMwTp7nYFLQg/j0VA2FmCY4WPDDHMg==
dependencies:
"@babel/runtime" "^7.13.10"
"@radix-ui/react-use-layout-effect" "1.0.0"

"@rocketseat/eslint-config@^1.1.3":
version "1.1.3"
resolved "https://registry.npmjs.org/@rocketseat/eslint-config/-/eslint-config-1.1.3.tgz"
Expand Down

0 comments on commit c1e86fc

Please sign in to comment.