Skip to content

Commit

Permalink
feat: added Checkbox component
Browse files Browse the repository at this point in the history
  • Loading branch information
aizad-deriv committed Feb 5, 2024
1 parent e7b7d12 commit 8a79474
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lib/components/Checkbox/Checkbox.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
$border_radius: 2px;
$border: 2px solid;
$border_color: #999999;
$brand_color: #ff444f;

.deriv-checkbox__wrapper {
display: inline-flex;
position: relative;
width: fit-content;
align-items: center;
justify-content: center;
gap: 8px;
}

.deriv-checkbox {
width: 16px;
height: 16px;
border-radius: $border_radius;
transition: background-color 0.3s ease;
cursor: pointer;

&--unchecked {
background: transparent;
border: $border $border_color;
}

&--checked {
border: none;
background-color: $brand_color;
background-image: url("./checkbox-icon.svg");
background-position: center;
background-repeat: no-repeat;
border-radius: $border_radius;
}

&__label {
flex-grow: 1;
}
}
1 change: 1 addition & 0 deletions lib/components/Checkbox/checkbox-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions lib/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { ComponentProps } from "react";
import clsx from "clsx";
import "./Checkbox.scss";

interface CheckboxProps extends Omit<ComponentProps<"input">, "placeholder"> {
wrapperClassName?: string;
}

export const Checkbox = ({
checked,
children,
className,
defaultChecked,
wrapperClassName,
...rest
}: CheckboxProps) => {
return (
<div className={clsx("deriv-checkbox__wrapper", wrapperClassName)}>
<input
checked={checked}
defaultChecked={defaultChecked}
className={clsx(
"deriv-checkbox",
{
"deriv-checkbox--unchecked": !checked,
"deriv-checkbox--checked": checked,
},
className
)}
type="checkbox"
{...rest}
/>
<span className="deriv-checkbox__icon"></span>
<label className="deriv-checkbox__label">{children}</label>
</div>
);
};
1 change: 1 addition & 0 deletions lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export { useDevice } from "./hooks/useDevice";
export { useOnClickOutside } from "./hooks/useOnClickOutside";
export { PasswordInput } from "./components/PasswordInput";
export { InlineMessage } from "./components/InlineMessage";
export { Checkbox } from "./components/Checkbox";

0 comments on commit 8a79474

Please sign in to comment.