Skip to content

Commit

Permalink
feat: 优化radio代码
Browse files Browse the repository at this point in the history
  • Loading branch information
busy-mango committed Sep 25, 2024
1 parent eecbd5a commit 3978583
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/widgets/radio/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
display: inline-block;

color: var(--secondary-color);
border-radius: var(--border-radius-10);

&.checked {
color: var(--secondary-color-active);
Expand Down
8 changes: 7 additions & 1 deletion src/components/widgets/radio/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ifnot } from '@busymango/utils';

import { onCheckCatch, useControlState } from '../control';
import { ISVGWrap } from '../svg-wrap';
import { IWave } from '../wave';
import { ICheckedSVG } from './icon';
import type {
IRadioInputRender,
Expand All @@ -25,9 +26,13 @@ const iRootRender: IRadioRootRender = ({ label, radio, ...others }) => (
</span>
);

const iRadioRender: IRadioRadioRender = ({ input, ...others }, { checked }) => (
const iRadioRender: IRadioRadioRender = (
{ input, inputRef, ...others },
{ checked }
) => (
<ISVGWrap {...others}>
<ICheckedSVG checked={checked} className={styles.icon} />
<IWave target={inputRef} />
{input}
</ISVGWrap>
);
Expand Down Expand Up @@ -103,6 +108,7 @@ export const IRadio = forwardRef<IRadioRef, IRadioProps>(
}),
radio: (render?.radio ?? iRadioRender)(
{
inputRef: input,
className: classNames(styles.radio),
input: (render?.input ?? iInputRender)(
{
Expand Down
5 changes: 4 additions & 1 deletion src/components/widgets/radio/models/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export type IRadioRootRender = ReactRender<
>;

export type IRadioRadioRender = ReactRender<
HTMLMotionProps<'i'> & { input: React.ReactNode },
HTMLMotionProps<'i'> & {
input: React.ReactNode;
inputRef: React.RefObject<HTMLInputElement>;
},
IRadioState
>;

Expand Down

0 comments on commit 3978583

Please sign in to comment.