feat: add radio group (#2572)

This commit is contained in:
Whitewater
2023-05-29 08:15:22 -07:00
committed by GitHub
parent 20cc082a02
commit 88eaaf9ce4
8 changed files with 198 additions and 4 deletions

View File

@@ -29,4 +29,4 @@ export const DropdownButton = forwardRef<
</button>
);
});
DropdownButton.displayName = 'SimpleDropdownButton';
DropdownButton.displayName = 'DropdownButton';

View File

@@ -0,0 +1,35 @@
import type {
RadioGroupItemProps,
RadioGroupProps,
} from '@radix-ui/react-radio-group';
import * as RadioGroup from '@radix-ui/react-radio-group';
import { forwardRef } from 'react';
import * as styles from './styles.css';
export const RadioButton = forwardRef<HTMLButtonElement, RadioGroupItemProps>(
({ children, ...props }, ref) => {
return (
<RadioGroup.Item ref={ref} {...props}>
<span className={styles.radioUncheckedButton}>{children}</span>
<RadioGroup.Indicator className={styles.radioButton}>
{children}
</RadioGroup.Indicator>
</RadioGroup.Item>
);
}
);
RadioButton.displayName = 'RadioButton';
export const RadioButtonGroup = forwardRef<HTMLDivElement, RadioGroupProps>(
({ ...props }, ref) => {
return (
<RadioGroup.Root
ref={ref}
className={styles.radioButtonGroup}
{...props}
></RadioGroup.Root>
);
}
);
RadioButtonGroup.displayName = 'RadioButtonGroup';

View File

@@ -52,3 +52,43 @@ export const icon = style({
},
},
});
export const radioButton = style({
fontSize: 'var(--affine-font-xs)',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: '75px',
height: '24px',
borderRadius: '8px',
filter: 'drop-shadow(0px 0px 4px rgba(0, 0, 0, 0.1))',
whiteSpace: 'nowrap',
userSelect: 'none',
selectors: {
'&:hover': {
background: 'var(--affine-hover-color)',
},
'&[data-state="checked"]': {
background: 'var(--affine-white)',
},
},
});
export const radioUncheckedButton = style([
radioButton,
{
selectors: {
'[data-state="checked"] > &': {
display: 'none',
},
},
},
]);
export const radioButtonGroup = style({
display: 'inline-flex',
alignItems: 'flex-start',
background: 'var(--affine-hover-color)',
borderRadius: '10px',
padding: '2px',
});