generated from abelflopes/lerna-monorepo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61550f5
commit fa39045
Showing
18 changed files
with
378 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/components/_provisional/src/boolean-input/BooleaInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import styles from "./styles/index.module.scss"; | ||
import React, { useMemo, useState } from "react"; | ||
import classNames from "classnames"; | ||
import { type FormFieldContextProps, useFormFieldContext } from "@react-ck/form-field"; | ||
import { type BooleanInputIconComponent } from "./types"; | ||
|
||
export interface BooleaInputProps extends React.ComponentProps<"input"> { | ||
Icon: BooleanInputIconComponent; | ||
skin?: FormFieldContextProps["skin"]; | ||
} | ||
|
||
export const BooleaInput = ({ | ||
Icon, | ||
skin, | ||
className, | ||
id, | ||
checked, | ||
value, | ||
name, | ||
onChange, | ||
...otherProps | ||
}: Readonly<BooleaInputProps>): React.ReactElement => { | ||
const formFieldContext = useFormFieldContext(); | ||
|
||
const computedId = useMemo(() => formFieldContext?.id ?? id, [formFieldContext?.id, id]); | ||
|
||
const [localChecked, setLocalChecked] = useState(Boolean(checked)); | ||
|
||
return ( | ||
<span className={classNames(styles.root, className)}> | ||
<input | ||
{...otherProps} | ||
id={computedId} | ||
name={name} | ||
checked={checked} | ||
value={value} | ||
className={styles.input} | ||
onChange={(e) => { | ||
onChange?.(e); | ||
setLocalChecked(e.target.checked); | ||
}} | ||
/> | ||
|
||
<Icon | ||
name={name} | ||
checked={localChecked} | ||
value={value} | ||
skin={skin ?? formFieldContext?.skin} | ||
/> | ||
</span> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./types"; | ||
|
||
export * from "./BooleaInput"; |
19 changes: 19 additions & 0 deletions
19
packages/components/_provisional/src/boolean-input/styles/index.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@use "@react-ck/theme"; | ||
|
||
.root { | ||
position: relative; | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.input { | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
height: 100%; | ||
width: 100%; | ||
appearance: none; | ||
cursor: pointer; | ||
z-index: 1; | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/components/_provisional/src/boolean-input/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { type FormFieldContextProps } from "@react-ck/form-field"; | ||
import { type ComponentProps } from "react"; | ||
|
||
interface BaseProps extends Required<Pick<ComponentProps<"input">, "checked" | "name" | "value">> { | ||
skin: FormFieldContextProps["skin"]; | ||
} | ||
|
||
export type BooleanInputIconProps = { | ||
[key in keyof BaseProps]: BaseProps[key] | undefined; | ||
}; | ||
|
||
export type BooleanInputIconComponent = (props: BooleanInputIconProps) => React.ReactNode; |
17 changes: 17 additions & 0 deletions
17
packages/components/_provisional/src/checkbox/CheckboxIconDefault.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import styles from "./styles/icon.module.scss"; | ||
import React from "react"; | ||
import { IconCheck } from "@react-ck/icon/icons/IconCheck"; | ||
import { Icon } from "@react-ck/icon"; | ||
import classNames from "classnames"; | ||
import { type BooleanInputIconComponent } from "../boolean-input"; | ||
|
||
export const CheckboxIconDefault: BooleanInputIconComponent = ({ checked }) => ( | ||
<span | ||
className={classNames(styles.root, { | ||
[`${styles.checked}`]: checked, | ||
})}> | ||
<Icon className={styles.icon}> | ||
<IconCheck /> | ||
</Icon> | ||
</span> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react"; | ||
import { CheckboxIconDefault } from "./CheckboxIconDefault"; | ||
import { BooleaInput, type BooleaInputProps } from "../boolean-input"; | ||
|
||
export type CheckboxProps = Omit<BooleaInputProps, "type" | "Icon"> & | ||
Partial<Pick<BooleaInputProps, "Icon">>; | ||
|
||
export const Checkbox = ({ | ||
Icon = CheckboxIconDefault, | ||
...otherProps | ||
}: Readonly<CheckboxProps>): React.ReactElement => ( | ||
<BooleaInput type="checkbox" Icon={Icon} {...otherProps} /> | ||
); |
23 changes: 23 additions & 0 deletions
23
packages/components/_provisional/src/checkbox/styles/icon.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@use "@react-ck/theme"; | ||
@use "@react-ck/scss-utils"; | ||
|
||
.root { | ||
display: inline-block; | ||
background-color: theme.get-color(neutral-light-1); | ||
border: theme.get-color(neutral-light-2) solid scss-utils.get-css-var(spacing, border); | ||
|
||
padding: theme.get-spacing(0.25); | ||
border-radius: theme.get-spacing(0.5); | ||
line-height: 0; | ||
|
||
&.checked .icon { | ||
transform: scale(1); | ||
} | ||
} | ||
|
||
.icon { | ||
transition: all 0.15s ease; | ||
will-change: transform; | ||
|
||
transform: scale(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/components/_provisional/src/radio/RadioIconDefault.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import styles from "./styles/icon.module.scss"; | ||
import React from "react"; | ||
import classNames from "classnames"; | ||
import { type BooleanInputIconComponent } from "../boolean-input"; | ||
|
||
export const RadioIconDefault: BooleanInputIconComponent = ({ checked }) => ( | ||
<span | ||
className={classNames(styles.root, { | ||
[`${styles.checked}`]: checked, | ||
})}> | ||
<span className={styles.icon} /> | ||
</span> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react"; | ||
import { RadioIconDefault } from "./RadioIconDefault"; | ||
import { BooleaInput, type BooleaInputProps } from "../boolean-input"; | ||
|
||
export type RadioProps = Omit<BooleaInputProps, "type" | "Icon"> & | ||
Partial<Pick<BooleaInputProps, "Icon">>; | ||
|
||
export const Radio = ({ | ||
Icon = RadioIconDefault, | ||
...otherProps | ||
}: Readonly<RadioProps>): React.ReactElement => ( | ||
<BooleaInput type="radio" Icon={Icon} {...otherProps} /> | ||
); |
28 changes: 28 additions & 0 deletions
28
packages/components/_provisional/src/radio/styles/icon.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@use "@react-ck/theme"; | ||
@use "@react-ck/scss-utils"; | ||
|
||
.root { | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: center; | ||
border: theme.get-color(neutral-light-2) solid scss-utils.get-css-var(spacing, border); | ||
padding: theme.get-spacing(0.5); | ||
border-radius: 50%; | ||
|
||
&.checked .icon { | ||
transform: scale(1); | ||
} | ||
} | ||
|
||
.icon { | ||
display: block; | ||
height: theme.get-spacing(1.4); | ||
width: theme.get-spacing(1.4); | ||
border-radius: 50%; | ||
background-color: theme.get-color(highlight-primary); | ||
|
||
transition: all 0.15s ease; | ||
will-change: transform; | ||
|
||
transform: scale(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.