From 2db9672f10de94934e7677c6fc2b811940710a06 Mon Sep 17 00:00:00 2001 From: lerte smith Date: Mon, 18 Nov 2024 11:09:36 +0800 Subject: [PATCH] radio component --- apps/docs/content/components/radio.md | 11 ++++---- apps/docs/src/usages/radio.tsx | 25 +++++++---------- .../src/components/Radio/RadioGroup.tsx | 27 +++++++++++++------ .../components/Radio/radio-group.module.css | 17 ++++++++++++ .../src/components/Radio/radio.module.css | 2 +- 5 files changed, 53 insertions(+), 29 deletions(-) create mode 100644 packages/actify/src/components/Radio/radio-group.module.css diff --git a/apps/docs/content/components/radio.md b/apps/docs/content/components/radio.md index 1e5a7e5..1122c3f 100644 --- a/apps/docs/content/components/radio.md +++ b/apps/docs/content/components/radio.md @@ -9,8 +9,9 @@ description: Radio buttons let people select one option from a set of options ## Props -| Props | Type | Description | Default | -| ------------ | ----------- | ----------------------------------------------------------------- | ----------- | -| `value` | `string` | The value of the radio button, used when submitting an HTML form. | `null` | -| `children` | `ReactNode` | The label for the Radio. Accepts any renderable node. | `undefined` | -| `isDisabled` | `boolean` | Whether the radio button is disabled or not. | `undefined` | +| Props | Type | Description | Default | +| ------------- | ----------------------- | ----------------------------------------------------------------- | ----------- | +| `value` | `string` | The value of the radio button, used when submitting an HTML form. | `null` | +| `children` | `ReactNode` | The label for the Radio. Accepts any renderable node. | `undefined` | +| `isDisabled` | `boolean` | Whether the radio button is disabled or not. | `undefined` | +| `orientation` | `horizontal` `vertical` | The axis the Radio should align with. | `vertical` | diff --git a/apps/docs/src/usages/radio.tsx b/apps/docs/src/usages/radio.tsx index 7e55338..ab2020e 100644 --- a/apps/docs/src/usages/radio.tsx +++ b/apps/docs/src/usages/radio.tsx @@ -3,32 +3,27 @@ import { Radio, RadioGroup } from 'actify' export default () => { return (
+

Radio With label

+ + + Actify + Ngroker + Taildoor + Hugola + +

RadioGroup With label

- -

Radio With label

- - - Actify - Ngroker - Taildoor - Hugola -
) } diff --git a/packages/actify/src/components/Radio/RadioGroup.tsx b/packages/actify/src/components/Radio/RadioGroup.tsx index c03b449..b6d8567 100644 --- a/packages/actify/src/components/Radio/RadioGroup.tsx +++ b/packages/actify/src/components/Radio/RadioGroup.tsx @@ -3,32 +3,43 @@ import { RadioGroupState, useRadioGroupState } from 'react-stately' import { Label } from '../Label' import React from 'react' +import { StyleProps } from '../../utils' +import clsx from 'clsx' +import styles from './radio-group.module.css' export const RadioContext = React.createContext({}) -interface RadioGroupProps extends AriaRadioGroupProps { - style?: React.CSSProperties - className?: string +interface RadioGroupProps extends AriaRadioGroupProps, StyleProps { children?: React.ReactNode } const RadioGroup = (props: RadioGroupProps) => { - const { style, className, description, errorMessage } = props + const { + style, + className, + description, + errorMessage, + orientation = 'vertical' + } = props const state = useRadioGroupState(props) const { radioGroupProps, labelProps, descriptionProps, errorMessageProps } = - useRadioGroup(props, state) + useRadioGroup({ ...props, orientation }, state) return ( -
+
{props.label && } {props.children} {description && ( -
+
{description}
)} {errorMessage && state.isInvalid && ( -
+
<>{errorMessage}
)} diff --git a/packages/actify/src/components/Radio/radio-group.module.css b/packages/actify/src/components/Radio/radio-group.module.css new file mode 100644 index 0000000..3c9efe9 --- /dev/null +++ b/packages/actify/src/components/Radio/radio-group.module.css @@ -0,0 +1,17 @@ +.radio-group { + display: flex; +} +.radio-group[aria-orientation='horizontal'] { + gap: 8px; + align-items: center; +} +.radio-group[aria-orientation='vertical'] { + flex-direction: column; +} +.description { + font-size: 12px; +} +.error-message { + font-size: 12px; + color: rgb(var(--md-sys-color-error)); +} diff --git a/packages/actify/src/components/Radio/radio.module.css b/packages/actify/src/components/Radio/radio.module.css index be10994..f3ed270 100644 --- a/packages/actify/src/components/Radio/radio.module.css +++ b/packages/actify/src/components/Radio/radio.module.css @@ -1,7 +1,7 @@ .radio-wrapper { gap: 8px; height: 48px; - display: flex; + display: inline-flex; align-items: center; } .radio {