Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions apps/docs/content/components/checkbox/colors.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Checkbox} from "@nextui-org/react";

export default function App() {
return (
<div className="flex gap-4">
<Checkbox defaultSelected color="default">
Default
</Checkbox>
<Checkbox defaultSelected color="primary">
Primary
</Checkbox>
<Checkbox defaultSelected color="secondary">
Secondary
</Checkbox>
<Checkbox defaultSelected color="success">
Success
</Checkbox>
<Checkbox defaultSelected color="warning">
Warning
</Checkbox>
<Checkbox defaultSelected color="danger">
Danger
</Checkbox>
</div>
);
}
15 changes: 1 addition & 14 deletions apps/docs/content/components/checkbox/colors.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
const App = `import {Checkbox} from "@nextui-org/react";

export default function App() {
return (
<div className="flex gap-4">
<Checkbox defaultSelected color="default">Default</Checkbox>
<Checkbox defaultSelected color="primary">Primary</Checkbox>
<Checkbox defaultSelected color="secondary">Secondary</Checkbox>
<Checkbox defaultSelected color="success">Success</Checkbox>
<Checkbox defaultSelected color="warning">Warning</Checkbox>
<Checkbox defaultSelected color="danger">Danger</Checkbox>
</div>
);
}`;
import App from "./colors.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
14 changes: 14 additions & 0 deletions apps/docs/content/components/checkbox/controlled.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Checkbox} from "@nextui-org/react";

export default function App() {
const [isSelected, setIsSelected] = React.useState(false);

return (
<div className="flex flex-col gap-2">
<Checkbox isSelected={isSelected} onValueChange={setIsSelected}>
Subscribe (controlled)
</Checkbox>
<p className="text-default-500">Selected: {isSelected ? "true" : "false"}</p>
</div>
);
}
17 changes: 1 addition & 16 deletions apps/docs/content/components/checkbox/controlled.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
const App = `import {Checkbox} from "@nextui-org/react";

export default function App() {
const [isSelected, setIsSelected] = React.useState(false);

return (
<div className="flex flex-col gap-2">
<Checkbox isSelected={isSelected} onValueChange={setIsSelected}>
Subscribe (controlled)
</Checkbox>
<p className="text-default-500">
Selected: {isSelected ? "true" : "false"}
</p>
</div>
);
}`;
import App from "./controlled.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
68 changes: 68 additions & 0 deletions apps/docs/content/components/checkbox/custom-check-icon.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {Checkbox} from "@nextui-org/react";

export const HeartIcon = ({size, height, width, ...props}) => {
// avoid passing non-DOM attributes to svg
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {isSelected, isIndeterminate, disableAnimation, ...otherProps} = props;

return (
<svg
fill="fill"
height={size || height || 24}
viewBox="0 0 24 24"
width={size || width || 24}
xmlns="http://www.w3.org/2000/svg"
{...otherProps}
>
<path
d="M12.62 20.81c-.34.12-.9.12-1.24 0C8.48 19.82 2 15.69 2 8.69 2 5.6 4.49 3.1 7.56 3.1c1.82 0 3.43.88 4.44 2.24a5.53 5.53 0 0 1 4.44-2.24C19.51 3.1 22 5.6 22 8.69c0 7-6.48 11.13-9.38 12.12Z"
fill="currentColor"
/>
</svg>
);
};

export const PlusIcon = ({size, height, width, ...props}) => {
// avoid passing non-DOM attributes to svg
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {isSelected, isIndeterminate, disableAnimation, ...otherProps} = props;

return (
<svg
fill="none"
height={size || height || 24}
viewBox="0 0 24 24"
width={size || width || 24}
xmlns="http://www.w3.org/2000/svg"
{...otherProps}
>
<path
d="M6 12H18"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="3"
/>
<path
d="M12 18V6"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="3"
/>
</svg>
);
};

export default function App() {
return (
<div className="flex gap-4">
<Checkbox defaultSelected icon={<HeartIcon />}>
Option
</Checkbox>
<Checkbox defaultSelected color="warning" icon={<PlusIcon />}>
Option
</Checkbox>
</div>
);
}
68 changes: 1 addition & 67 deletions apps/docs/content/components/checkbox/custom-check-icon.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,7 @@
const HeartIcon = `export const HeartIcon = ({ size, height, width, ...props }) => {
// avoid passing non-DOM attributes to svg
const {isSelected, isIndeterminate, disableAnimation, ...otherProps} = props;

return (
<svg
width={size || width || 24}
height={size || height || 24}
viewBox="0 0 24 24"
fill='fill'
xmlns="http://www.w3.org/2000/svg"
{...otherProps}
>
<path
d="M12.62 20.81c-.34.12-.9.12-1.24 0C8.48 19.82 2 15.69 2 8.69 2 5.6 4.49 3.1 7.56 3.1c1.82 0 3.43.88 4.44 2.24a5.53 5.53 0 0 1 4.44-2.24C19.51 3.1 22 5.6 22 8.69c0 7-6.48 11.13-9.38 12.12Z"
fill='currentColor'
/>
</svg>
);
};
`;

const PlusIcon = `export const PlusIcon = ({ size, height, width, ...props }) => {
// avoid passing non-DOM attributes to svg
const {isSelected, isIndeterminate, disableAnimation, ...otherProps} = props;

return (
<svg
width={size || width || 24}
height={size || height || 24}
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
{...otherProps}
>
<path
d="M6 12H18"
stroke="currentColor"
stroke-width="3"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
d="M12 18V6"
stroke="currentColor"
stroke-width="3"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
);
};`;

const App = `import {Checkbox} from "@nextui-org/react";
import {HeartIcon} from './HeartIcon.jsx';
import {PlusIcon} from './PlusIcon.jsx';

export default function App() {
return (
<div className="flex gap-4">
<Checkbox defaultSelected icon={<HeartIcon/>}>Option</Checkbox>
<Checkbox defaultSelected icon={<PlusIcon/>} color="warning">Option</Checkbox>
</div>
);
}`;
import App from "./custom-check-icon.raw.jsx?raw";

const react = {
"/App.jsx": App,
"/HeartIcon.jsx": HeartIcon,
"/PlusIcon.jsx": PlusIcon,
};

export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {useCheckbox, Chip, VisuallyHidden, tv} from "@nextui-org/react";

export const CheckIcon = (props) => (
<svg
aria-hidden="true"
fill="none"
focusable="false"
height="1em"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
viewBox="0 0 24 24"
width="1em"
{...props}
>
<polyline points="20 6 9 17 4 12" />
</svg>
);

const checkbox = tv({
slots: {
base: "border-default hover:bg-default-200",
content: "text-default-500",
},
variants: {
isSelected: {
true: {
base: "border-primary bg-primary hover:bg-primary-500 hover:border-primary-500",
content: "text-primary-foreground pl-1",
},
},
isFocusVisible: {
true: {
base: "outline-none ring-2 ring-focus ring-offset-2 ring-offset-background",
},
},
},
});

export default function App() {
const {children, isSelected, isFocusVisible, getBaseProps, getLabelProps, getInputProps} =
useCheckbox({
defaultSelected: true,
});

const styles = checkbox({isSelected, isFocusVisible});

return (
<label {...getBaseProps()}>
<VisuallyHidden>
<input {...getInputProps()} />
</VisuallyHidden>
<Chip
classNames={{
base: styles.base(),
content: styles.content(),
}}
color="primary"
startContent={isSelected ? <CheckIcon className="ml-1" /> : null}
variant="faded"
{...getLabelProps()}
>
{children ? children : isSelected ? "Enabled" : "Disabled"}
</Chip>
</label>
);
}
78 changes: 1 addition & 77 deletions apps/docs/content/components/checkbox/custom-implementation.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,7 @@
const CheckIcon = `export const CheckIcon = (props) =>
(
<svg
aria-hidden="true"
fill="none"
focusable="false"
height="1em"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
viewBox="0 0 24 24"
width="1em"
{...props}
>
<polyline points="20 6 9 17 4 12" />
</svg>
);`;

const App = `import {useCheckbox, Chip, VisuallyHidden, tv} from "@nextui-org/react";
import {CheckIcon} from './CheckIcon.jsx'

const checkbox = tv({
slots: {
base: "border-default hover:bg-default-200",
content: "text-default-500"
},
variants: {
isSelected: {
true: {
base: "border-primary bg-primary hover:bg-primary-500 hover:border-primary-500",
content: "text-primary-foreground pl-1"
}
},
isFocusVisible: {
true: {
base: "outline-none ring-2 ring-focus ring-offset-2 ring-offset-background",
}
}
}
})

export default function App() {
const {
children,
isSelected,
isFocusVisible,
getBaseProps,
getLabelProps,
getInputProps,
} = useCheckbox({
defaultSelected: true,
})

const styles = checkbox({ isSelected, isFocusVisible })

return (
<label {...getBaseProps()}>
<VisuallyHidden>
<input {...getInputProps()} />
</VisuallyHidden>
<Chip
classNames={{
base: styles.base(),
content: styles.content(),
}}
color="primary"
startContent={isSelected ? <CheckIcon className="ml-1" /> : null}
variant="faded"
{...getLabelProps()}
>
{children ? children : isSelected ? "Enabled" : "Disabled"}
</Chip>
</label>
);
}`;
import App from "./custom-implementation.raw.jsx?raw";

const react = {
"/App.jsx": App,
"./CheckIcon.jsx": CheckIcon,
};

export default {
Expand Down
Loading