Skip to content

Commit

Permalink
feat(mobile): added checkbox common componnet
Browse files Browse the repository at this point in the history
  • Loading branch information
janhvipatil committed Dec 19, 2024
1 parent 55b3182 commit 4e0f402
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
52 changes: 52 additions & 0 deletions apps/mobile/components/nativewindui/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as CheckboxPrimitive from '@rn-primitives/checkbox';
import { useControllableState } from '@rn-primitives/hooks';
import * as React from 'react';
import CheckIcon from '@assets/icons/CheckIcon.svg';

import { cn } from '@lib/cn';
import { COLORS } from '@theme/colors';

type CheckboxProps = Omit<CheckboxPrimitive.RootProps, 'checked' | 'onCheckedChange'> & {
defaultChecked?: boolean;
checked?: boolean;
onCheckedChange?: (checked: boolean) => void;
};

const Checkbox = React.forwardRef<CheckboxPrimitive.RootRef, CheckboxProps>(
(
{
className,
checked: checkedProps,
onCheckedChange: onCheckedChangeProps,
defaultChecked = false,
...props
},
ref
) => {
const [checked = false, onCheckedChange] = useControllableState({
prop: checkedProps,
defaultProp: defaultChecked,
onChange: onCheckedChangeProps,
});
return (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
'ios:rounded-full ios:h-[22px] ios:w-[22px] border-muted-foreground h-[18px] w-[18px] rounded-sm border',
checked && 'bg-primary border-0',
props.disabled && 'opacity-50',
className
)}
checked={checked}
onCheckedChange={onCheckedChange}
{...props}>
<CheckboxPrimitive.Indicator className={cn('h-full w-full items-center justify-center')}>
<CheckIcon color={COLORS.white} />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
);
}
);
Checkbox.displayName = CheckboxPrimitive.Root.displayName;

export { Checkbox };
1 change: 1 addition & 0 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@react-navigation/drawer": "^7.1.1",
"@rn-primitives/alert-dialog": "^1.1.0",
"@rn-primitives/avatar": "^1.1.0",
"@rn-primitives/checkbox": "^1.1.0",
"@rn-primitives/dropdown-menu": "^1.1.0",
"@rn-primitives/hooks": "^1.1.0",
"@rn-primitives/portal": "^1.1.0",
Expand Down
29 changes: 29 additions & 0 deletions apps/mobile/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,20 @@
dependencies:
"@radix-ui/react-primitive" "2.0.1"

"@radix-ui/react-checkbox@^1.1.1":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@radix-ui/react-checkbox/-/react-checkbox-1.1.3.tgz#0e2ab913fddf3c88603625f7a9457d73882c8a32"
integrity sha512-HD7/ocp8f1B3e6OHygH0n7ZKjONkhciy1Nh0yuBgObqThc3oyx+vuMfFHKAknXRHHWVE9XvXStxJFyjUmB8PIw==
dependencies:
"@radix-ui/primitive" "1.1.1"
"@radix-ui/react-compose-refs" "1.1.1"
"@radix-ui/react-context" "1.1.1"
"@radix-ui/react-presence" "1.1.2"
"@radix-ui/react-primitive" "2.0.1"
"@radix-ui/react-use-controllable-state" "1.1.0"
"@radix-ui/react-use-previous" "1.1.0"
"@radix-ui/react-use-size" "1.1.0"

"@radix-ui/react-collection@1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@radix-ui/react-collection/-/react-collection-1.1.1.tgz#be2c7e01d3508e6d4b6d838f492e7d182f17d3b0"
Expand Down Expand Up @@ -1637,6 +1651,11 @@
resolved "https://registry.yarnpkg.com/@radix-ui/react-use-layout-effect/-/react-use-layout-effect-1.1.0.tgz#3c2c8ce04827b26a39e442ff4888d9212268bd27"
integrity sha512-+FPE0rOdziWSrH9athwI1R0HDVbWlEhd+FR+aSDk4uWGmSJ9Z54sdZVDQPZAinJhJXwfT+qnj969mCsT2gfm5w==

"@radix-ui/react-use-previous@1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@radix-ui/react-use-previous/-/react-use-previous-1.1.0.tgz#d4dd37b05520f1d996a384eb469320c2ada8377c"
integrity sha512-Z/e78qg2YFnnXcW88A4JmTtm4ADckLno6F7OXotmkQfeuCVaKuYzqAATPhVzl3delXE7CxIV8shofPn3jPc5Og==

"@radix-ui/react-use-rect@1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@radix-ui/react-use-rect/-/react-use-rect-1.1.0.tgz#13b25b913bd3e3987cc9b073a1a164bb1cf47b88"
Expand Down Expand Up @@ -1979,6 +1998,16 @@
"@rn-primitives/slot" "1.1.0"
"@rn-primitives/types" "1.1.0"

"@rn-primitives/checkbox@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@rn-primitives/checkbox/-/checkbox-1.1.0.tgz#3c6839227d8039b58658566a943505d980c23d1f"
integrity sha512-drIWeB41LOkkGDHUKM++7e5vuODB6KeX7qJR3JfYoF0FDRGMG23f3cCo6cQy6DNgsjBctGPpTojQQxuLjuuTWg==
dependencies:
"@radix-ui/react-checkbox" "^1.1.1"
"@rn-primitives/hooks" "1.1.0"
"@rn-primitives/slot" "1.1.0"
"@rn-primitives/types" "1.1.0"

"@rn-primitives/dropdown-menu@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@rn-primitives/dropdown-menu/-/dropdown-menu-1.1.0.tgz#deda32f14ae830278d13bc162d1ebbf23fec814c"
Expand Down

0 comments on commit 4e0f402

Please sign in to comment.