diff --git a/packages/mini-demo/src/app.config.ts b/packages/mini-demo/src/app.config.ts index 8dbac41b2..e733e8a0f 100644 --- a/packages/mini-demo/src/app.config.ts +++ b/packages/mini-demo/src/app.config.ts @@ -5,6 +5,7 @@ export default defineAppConfig({ 'pages/popup/index', 'pages/list/index', 'pages/collapse/index', + 'pages/radio/index', 'pages/tabs/index', ], window: { diff --git a/packages/mini-demo/src/pages/radio/component/basic.tsx b/packages/mini-demo/src/pages/radio/component/basic.tsx new file mode 100644 index 000000000..8d7d0f900 --- /dev/null +++ b/packages/mini-demo/src/pages/radio/component/basic.tsx @@ -0,0 +1,27 @@ +import * as React from 'react'; +import { List, Panel, Radio } from 'zarm/mini'; + +const Demo = () => { + return ( + + + + 普通 + + + 默认选中 + + + 禁用 + + + + 选中且禁用 + + + + + ); +}; + +export default Demo; diff --git a/packages/mini-demo/src/pages/radio/component/button.tsx b/packages/mini-demo/src/pages/radio/component/button.tsx new file mode 100644 index 000000000..41fccbfc5 --- /dev/null +++ b/packages/mini-demo/src/pages/radio/component/button.tsx @@ -0,0 +1,39 @@ +import * as React from 'react'; +import { List, Panel, Radio } from 'zarm/mini'; + +const Demo = () => { + return ( + + + + 选项一 + 选项二 + 选项三 + + + + + 选项一 + 选项二 + 选项三 + + + + + 选项一 + 选项二 + 选项三 + + + + + 选项一 + 选项二 + 选项三 + + + + ); +}; + +export default Demo; diff --git a/packages/mini-demo/src/pages/radio/component/group.tsx b/packages/mini-demo/src/pages/radio/component/group.tsx new file mode 100644 index 000000000..78c0f2b32 --- /dev/null +++ b/packages/mini-demo/src/pages/radio/component/group.tsx @@ -0,0 +1,27 @@ +import * as React from 'react'; +import { List, Panel, Radio } from 'zarm/mini'; + +const Demo = () => { + const [value, setValue] = React.useState([]); + + const onChange = (val) => { + console.log('onChange', val); + setValue(val); + }; + + return ( + + + + + 选项一 + 选项二 + 选项三 + + + + + ); +}; + +export default Demo; diff --git a/packages/mini-demo/src/pages/radio/component/list.tsx b/packages/mini-demo/src/pages/radio/component/list.tsx new file mode 100644 index 000000000..4d6c30e9b --- /dev/null +++ b/packages/mini-demo/src/pages/radio/component/list.tsx @@ -0,0 +1,28 @@ +import * as React from 'react'; +import { List, Panel, Radio } from 'zarm/mini'; + +const Demo = () => { + return ( + <> + + + 选项一 + 选项二 + + 选项三(禁止选择) + + + + + + + 选项一 + 选项二 + + + + + ); +}; + +export default Demo; diff --git a/packages/mini-demo/src/pages/radio/index.config.ts b/packages/mini-demo/src/pages/radio/index.config.ts new file mode 100644 index 000000000..90dd9fb8a --- /dev/null +++ b/packages/mini-demo/src/pages/radio/index.config.ts @@ -0,0 +1,3 @@ +export default definePageConfig({ + navigationBarTitleText: 'Radio', +}); diff --git a/packages/mini-demo/src/pages/radio/index.tsx b/packages/mini-demo/src/pages/radio/index.tsx new file mode 100644 index 000000000..137664e4b --- /dev/null +++ b/packages/mini-demo/src/pages/radio/index.tsx @@ -0,0 +1,16 @@ +import * as React from 'react'; +import Basic from './component/basic'; +import Button from './component/button'; +import Group from './component/group'; +import List from './component/list'; + +export default () => { + return ( + <> + + + + + + ); + } + + if (groupContext?.type === 'list') { + const tickRender = ( + <> + {inputRender} + {iconRender} + + ); + + return ( + { + if (disabled) return; + props.onChange?.({ + target: { value: props.value, checked: true }, + } as ChangeEvent); + setChecked(true); + } + : undefined + } + /> + ); + } + + const contentRender = props.render ? ( + props.render(currentProps) + ) : ( + { + if (disabled) return; + if (!('checked' in props)) { + setChecked(true); + } + props.onChange?.({ + target: { value: props.value, checked: true }, + } as ChangeEvent); + }} + > + {iconRender} + {textRender} + + ); + + return ( + + ); +}); + +Radio.displayName = 'Radio'; + +Radio.defaultProps = { + indeterminate: false, +}; + +export default Radio; diff --git a/packages/zarm/src/radio/demo/basic.mini.tsx b/packages/zarm/src/radio/demo/basic.mini.tsx new file mode 100644 index 000000000..8d7d0f900 --- /dev/null +++ b/packages/zarm/src/radio/demo/basic.mini.tsx @@ -0,0 +1,27 @@ +import * as React from 'react'; +import { List, Panel, Radio } from 'zarm/mini'; + +const Demo = () => { + return ( + + + + 普通 + + + 默认选中 + + + 禁用 + + + + 选中且禁用 + + + + + ); +}; + +export default Demo; diff --git a/packages/zarm/src/radio/demo/button.mini.tsx b/packages/zarm/src/radio/demo/button.mini.tsx new file mode 100644 index 000000000..41fccbfc5 --- /dev/null +++ b/packages/zarm/src/radio/demo/button.mini.tsx @@ -0,0 +1,39 @@ +import * as React from 'react'; +import { List, Panel, Radio } from 'zarm/mini'; + +const Demo = () => { + return ( + + + + 选项一 + 选项二 + 选项三 + + + + + 选项一 + 选项二 + 选项三 + + + + + 选项一 + 选项二 + 选项三 + + + + + 选项一 + 选项二 + 选项三 + + + + ); +}; + +export default Demo; diff --git a/packages/zarm/src/radio/demo/group.mini.tsx b/packages/zarm/src/radio/demo/group.mini.tsx new file mode 100644 index 000000000..78c0f2b32 --- /dev/null +++ b/packages/zarm/src/radio/demo/group.mini.tsx @@ -0,0 +1,27 @@ +import * as React from 'react'; +import { List, Panel, Radio } from 'zarm/mini'; + +const Demo = () => { + const [value, setValue] = React.useState([]); + + const onChange = (val) => { + console.log('onChange', val); + setValue(val); + }; + + return ( + + + + + 选项一 + 选项二 + 选项三 + + + + + ); +}; + +export default Demo; diff --git a/packages/zarm/src/radio/demo/list.mini.tsx b/packages/zarm/src/radio/demo/list.mini.tsx new file mode 100644 index 000000000..4d6c30e9b --- /dev/null +++ b/packages/zarm/src/radio/demo/list.mini.tsx @@ -0,0 +1,28 @@ +import * as React from 'react'; +import { List, Panel, Radio } from 'zarm/mini'; + +const Demo = () => { + return ( + <> + + + 选项一 + 选项二 + + 选项三(禁止选择) + + + + + + + 选项一 + 选项二 + + + + + ); +}; + +export default Demo; diff --git a/packages/zarm/src/radio/index.mini.ts b/packages/zarm/src/radio/index.mini.ts new file mode 100644 index 000000000..74cdb9da1 --- /dev/null +++ b/packages/zarm/src/radio/index.mini.ts @@ -0,0 +1,10 @@ +import attachPropertiesToComponent from '../utils/attachPropertiesToComponent'; +import Radio from './Radio.mini'; +import Group from './RadioGroup'; + +export type { RadioCssVars, RadioProps, RadioRef } from './Radio.mini'; +export type { RadioGroupCssVars, RadioGroupProps } from './RadioGroup'; + +export default attachPropertiesToComponent(Radio, { + Group, +}); diff --git a/packages/zarm/src/radio/style/index.mini.ts b/packages/zarm/src/radio/style/index.mini.ts new file mode 100644 index 000000000..5229a6cd9 --- /dev/null +++ b/packages/zarm/src/radio/style/index.mini.ts @@ -0,0 +1,5 @@ +import '../../button/style/index.mini'; +import '../../icon/style'; +import '../../list/style/index.mini'; +import '../../style'; +import './index.scss';