-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add CheckboxCard, CheckboxIndicator, RadioCard, RadioIndicator #486
- Loading branch information
Showing
12 changed files
with
456 additions
and
5 deletions.
There are no files selected for viewing
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
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,59 @@ | ||
import { | ||
CheckboxCard as MantineCheckboxCard, | ||
MantineRadius, | ||
MantineSize, | ||
} from "@mantine/core"; | ||
import { BoxProps } from "props/box"; | ||
import { DashBaseProps, PersistenceProps } from "props/dash"; | ||
import { StylesApiProps } from "props/styles"; | ||
import React from "react"; | ||
import { setPersistence, getLoadingState } from "../../../utils/dash3"; | ||
|
||
interface Props | ||
extends BoxProps, | ||
StylesApiProps, | ||
DashBaseProps, | ||
PersistenceProps { | ||
/** State of check box */ | ||
checked?: boolean; | ||
/** Uncontrolled component default value */ | ||
defaultChecked?: boolean; | ||
/** Determines whether the card should have border, `true` by default */ | ||
withBorder?: boolean; | ||
/** Key of `theme.radius` or any valid CSS value to set `border-radius,` `theme.defaultRadius` by default */ | ||
radius?: MantineRadius; | ||
/** To be used with checkbox group */ | ||
value?: string; | ||
/** Props passed down to the root element */ | ||
wrapperProps?: Record<string, any>; | ||
/** Determines whether CheckboxCard is disabled and non-selectable */ | ||
disabled?: boolean; | ||
/** CheckboxCard content */ | ||
children?: React.ReactNode; | ||
} | ||
|
||
/** CheckboxCard */ | ||
const CheckboxCard = ({ | ||
children, | ||
setProps, | ||
loading_state, | ||
persistence, | ||
persisted_props, | ||
persistence_type, | ||
...others | ||
}: Props) => { | ||
|
||
return ( | ||
<MantineCheckboxCard | ||
data-dash-is-loading={getLoadingState(loading_state) || undefined} | ||
onChange={(state: boolean) => setProps({ checked: state })} | ||
{...others} | ||
> | ||
{children} | ||
</MantineCheckboxCard> | ||
); | ||
}; | ||
|
||
setPersistence(CheckboxCard, ["checked"]); | ||
|
||
export default CheckboxCard; |
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,71 @@ | ||
import { | ||
CheckboxIndicator as MantineCheckboxIndicator, | ||
MantineColor, | ||
MantineRadius, | ||
MantineSize, | ||
} from "@mantine/core"; | ||
import { BoxProps } from "props/box"; | ||
import { DashBaseProps, PersistenceProps } from "props/dash"; | ||
import { StylesApiProps } from "props/styles"; | ||
import React from "react"; | ||
import { setPersistence, getLoadingState, applyDashProps } from "../../../utils/dash3"; | ||
|
||
interface Props | ||
extends BoxProps, | ||
StylesApiProps, | ||
DashBaseProps, | ||
PersistenceProps { | ||
/** Key of `theme.colors` or any valid CSS color to set input background color in checked state, `theme.primaryColor` by default */ | ||
color?: MantineColor; | ||
/** Controls size of the component, `'sm'` by default */ | ||
size?: MantineSize | (string & {}); | ||
/** Key of `theme.radius` or any valid CSS value to set `border-radius,` `theme.defaultRadius` by default */ | ||
radius?: MantineRadius; | ||
/** Props passed down to the root element */ | ||
wrapperProps?: Record<string, any>; | ||
/** Indeterminate state of the checkbox. If set, `checked` prop is ignored. */ | ||
indeterminate?: boolean; | ||
/** Key of `theme.colors` or any valid CSS color to set icon color, by default value depends on `theme.autoContrast` */ | ||
iconColor?: MantineColor; | ||
/** Determines whether icon color with filled variant should depend on `background-color`. If luminosity of the `color` prop is less than `theme.luminosityThreshold`, then `theme.white` will be used for text color, otherwise `theme.black`. Overrides `theme.autoContrast`. */ | ||
autoContrast?: boolean; | ||
/** State of check box */ | ||
checked?: boolean; | ||
/** Whether component is disabled */ | ||
disabled?: boolean; | ||
/** Icon */ | ||
icon?: React.ReactNode; | ||
/** Indeterminate icon */ | ||
indeterminateIcon?: React.ReactNode; | ||
} | ||
|
||
/** CheckboxIndicator */ | ||
const CheckboxIndicator = ({ | ||
setProps, | ||
loading_state, | ||
persistence, | ||
persisted_props, | ||
persistence_type, | ||
icon, | ||
indeterminateIcon, | ||
...others | ||
}: Props) => { | ||
|
||
|
||
const iconFunc = ({ indeterminate, ...others }) => { | ||
const selected: any = indeterminate ? indeterminateIcon : icon; | ||
return applyDashProps(selected, others); | ||
}; | ||
|
||
return ( | ||
<MantineCheckboxIndicator | ||
data-dash-is-loading={getLoadingState(loading_state) || undefined} | ||
icon={icon || indeterminateIcon ? iconFunc : undefined} | ||
{...others} | ||
/> | ||
); | ||
}; | ||
|
||
setPersistence(CheckboxIndicator, ["checked"] ) | ||
|
||
export default CheckboxIndicator; |
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
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,64 @@ | ||
import { | ||
RadioCard as MantineRadioCard, | ||
MantineRadius, | ||
} from "@mantine/core"; | ||
import { BoxProps } from "props/box"; | ||
import { DashBaseProps, PersistenceProps } from "props/dash"; | ||
import { StylesApiProps } from "props/styles"; | ||
import React from "react"; | ||
import { setPersistence, getLoadingState } from "../../../utils/dash3"; | ||
import RadioGroupContext from "./RadioGroupContext"; | ||
|
||
interface Props | ||
extends BoxProps, | ||
StylesApiProps, | ||
DashBaseProps, | ||
PersistenceProps { | ||
/** Checked state */ | ||
checked?: boolean; | ||
/** Determines whether the card should have border, `true` by default */ | ||
withBorder?: boolean; | ||
/** Key of `theme.radius` or any valid CSS value to set `border-radius,` "xl" by default */ | ||
radius?: MantineRadius; | ||
/** To be used with Radio group */ | ||
value?: string; | ||
/** Value used to associate all related radio cards, required for accessibility if used outside of `Radio.Group` */ | ||
name?: string; | ||
/** Props passed down to the root element */ | ||
wrapperProps?: Record<string, any>; | ||
/** Determines whether RadioCard is disabled and non-selectable */ | ||
disabled?: boolean; | ||
/** RadioCard content */ | ||
children?: React.ReactNode; | ||
} | ||
|
||
/** RadioCard */ | ||
const RadioCard = (props: Props) => { | ||
const { | ||
children, | ||
setProps, | ||
loading_state, | ||
persistence, | ||
persisted_props, | ||
persistence_type, | ||
value, | ||
...others | ||
} = props; | ||
|
||
const { radioOnClick } = React.useContext(RadioGroupContext) || {}; | ||
|
||
return ( | ||
<MantineRadioCard | ||
data-dash-is-loading={getLoadingState(loading_state) || undefined} | ||
onClick={radioOnClick ? () => radioOnClick(value) : null} | ||
value={value} | ||
{...others} | ||
> | ||
{children} | ||
</MantineRadioCard> | ||
); | ||
}; | ||
|
||
setPersistence(RadioCard, ["checked"]); | ||
|
||
export default RadioCard; |
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
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
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,57 @@ | ||
import { | ||
MantineColor, | ||
RadioIndicator as MantineRadioIndicator, | ||
MantineRadius, | ||
MantineSize, | ||
} from "@mantine/core"; | ||
import { BoxProps } from "props/box"; | ||
import { DashBaseProps, PersistenceProps } from "props/dash"; | ||
import { StylesApiProps } from "props/styles"; | ||
import React from "react"; | ||
import { setPersistence, getLoadingState } from "../../../utils/dash3"; | ||
|
||
interface Props | ||
extends BoxProps, | ||
StylesApiProps, | ||
DashBaseProps, | ||
PersistenceProps { | ||
/** Key of `theme.colors` or any valid CSS color to set input color in checked state, `theme.primaryColor` by default */ | ||
color?: MantineColor; | ||
/** Controls size of the component, `'sm'` by default */ | ||
size?: MantineSize; | ||
/** Props passed down to the root element */ | ||
wrapperProps?: Record<string, any>; | ||
/** Key of `theme.radius` or any valid CSS value to set `border-radius,` "xl" by default */ | ||
radius?: MantineRadius; | ||
/** Key of `theme.colors` or any valid CSS color to set icon color, by default value depends on `theme.autoContrast` */ | ||
iconColor?: MantineColor; | ||
/** Determines whether icon color with filled variant should depend on `background-color`. If luminosity of the `color` prop is less than `theme.luminosityThreshold`, then `theme.white` will be used for text color, otherwise `theme.black`. Overrides `theme.autoContrast`. */ | ||
autoContrast?: boolean; | ||
/** Determines whether the component should have checked styles */ | ||
checked?: boolean; | ||
/** Determines whether Radio disabled and non-selectable */ | ||
disabled?: boolean; | ||
} | ||
|
||
/** RadioIndicator */ | ||
const RadioIndicator = (props: Props) => { | ||
const { | ||
setProps, | ||
loading_state, | ||
persistence, | ||
persisted_props, | ||
persistence_type, | ||
...others | ||
} = props; | ||
|
||
return ( | ||
<MantineRadioIndicator | ||
data-dash-is-loading={getLoadingState(loading_state) || undefined} | ||
{...others} | ||
/> | ||
); | ||
}; | ||
|
||
setPersistence(RadioIndicator, ['checked']) | ||
|
||
export default RadioIndicator; |
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.