-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve(style): Multiple item background and border color for Select,…
… TreeSelect and Cascader
- Loading branch information
1 parent
ee8485f
commit 7c3c296
Showing
12 changed files
with
280 additions
and
46 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,53 @@ | ||
import React from 'react'; | ||
import { Cascader } from '@oceanbase/design'; | ||
|
||
interface Option { | ||
value: string | number; | ||
label: string; | ||
children?: Option[]; | ||
} | ||
|
||
const options: Option[] = [ | ||
{ | ||
value: 'zhejiang', | ||
label: 'Zhejiang', | ||
children: [ | ||
{ | ||
value: 'hangzhou', | ||
label: 'Hangzhou', | ||
children: [ | ||
{ | ||
value: 'xihu', | ||
label: 'West Lake', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
value: 'jiangsu', | ||
label: 'Jiangsu', | ||
children: [ | ||
{ | ||
value: 'nanjing', | ||
label: 'Nanjing', | ||
children: [ | ||
{ | ||
value: 'zhonghuamen', | ||
label: 'Zhong Hua Men', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const onChange = (value: (string | number)[]) => { | ||
console.log(value); | ||
}; | ||
|
||
const App: React.FC = () => ( | ||
<Cascader options={options} onChange={onChange} placeholder="Please select" /> | ||
); | ||
|
||
export default App; |
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,65 @@ | ||
import React from 'react'; | ||
import { Cascader } from '@oceanbase/design'; | ||
import type { MultipleCascaderProps } from '@oceanbase/design/es/cascader'; | ||
|
||
interface Option { | ||
value: string | number; | ||
label: string; | ||
children?: Option[]; | ||
disableCheckbox?: boolean; | ||
} | ||
|
||
const options: Option[] = [ | ||
{ | ||
label: 'Light', | ||
value: 'light', | ||
children: new Array(20) | ||
.fill(null) | ||
.map((_, index) => ({ label: `Number ${index}`, value: index })), | ||
}, | ||
{ | ||
label: 'Bamboo', | ||
value: 'bamboo', | ||
children: [ | ||
{ | ||
label: 'Little', | ||
value: 'little', | ||
children: [ | ||
{ | ||
label: 'Toy Fish', | ||
value: 'fish', | ||
disableCheckbox: true, | ||
}, | ||
{ | ||
label: 'Toy Cards', | ||
value: 'cards', | ||
}, | ||
{ | ||
label: 'Toy Bird', | ||
value: 'bird', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const onChange: MultipleCascaderProps<Option>['onChange'] = value => { | ||
console.log(value); | ||
}; | ||
|
||
const App: React.FC = () => ( | ||
<Cascader | ||
style={{ width: '100%' }} | ||
options={options} | ||
onChange={onChange} | ||
multiple | ||
maxTagCount="responsive" | ||
defaultValue={[ | ||
['light', 0], | ||
['light', 1], | ||
]} | ||
/> | ||
); | ||
|
||
export default App; |
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,21 @@ | ||
--- | ||
title: Cascader 级联选择 | ||
nav: | ||
title: 基础组件 | ||
path: /components | ||
demo: | ||
cols: 2 | ||
--- | ||
|
||
- 🔥 完全继承 antd [Cascader](https://ant.design/components/cascader-cn) 的能力和 API,可无缝切换。 | ||
- 💄 定制主题和样式,符合 OceanBase Design 设计规范。 | ||
|
||
## 代码演示 | ||
|
||
<!-- prettier-ignore --> | ||
<code src="./demo/basic.tsx" title="基本"></code> | ||
<code src="./demo/multiple.tsx" title="多选"></code> | ||
|
||
## API | ||
|
||
- 详见 antd InputNumber 文档: https://ant.design/components/input-number-cn |
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,39 @@ | ||
import React from 'react'; | ||
import { Select, Space } from '@oceanbase/design'; | ||
import type { SelectProps } from '@oceanbase/design'; | ||
|
||
const options: SelectProps['options'] = []; | ||
|
||
for (let i = 10; i < 36; i++) { | ||
options.push({ | ||
label: i.toString(36) + i, | ||
value: i.toString(36) + i, | ||
}); | ||
} | ||
|
||
const handleChange = (value: string[]) => { | ||
console.log(`selected ${value}`); | ||
}; | ||
|
||
const App: React.FC = () => ( | ||
<Space style={{ width: '100%' }} direction="vertical"> | ||
<Select | ||
mode="multiple" | ||
allowClear | ||
style={{ width: '100%' }} | ||
defaultValue={['a10', 'c12']} | ||
onChange={handleChange} | ||
options={options} | ||
/> | ||
<Select | ||
mode="multiple" | ||
disabled | ||
style={{ width: '100%' }} | ||
defaultValue={['a10', 'c12']} | ||
onChange={handleChange} | ||
options={options} | ||
/> | ||
</Space> | ||
); | ||
|
||
export default App; |
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,79 @@ | ||
import React from 'react'; | ||
import { Flex, Select } from '@oceanbase/design'; | ||
|
||
const App: React.FC = () => ( | ||
<Flex gap={12} vertical> | ||
<Flex gap={8}> | ||
<Select | ||
placeholder="Outlined" | ||
style={{ flex: 1 }} | ||
options={[ | ||
{ value: 'jack', label: 'Jack' }, | ||
{ value: 'lucy', label: 'Lucy' }, | ||
{ value: 'Yiminghe', label: 'yiminghe' }, | ||
]} | ||
/> | ||
<Select | ||
mode="multiple" | ||
defaultValue={['lucy']} | ||
placeholder="Outlined" | ||
style={{ flex: 1 }} | ||
options={[ | ||
{ value: 'jack', label: 'Jack' }, | ||
{ value: 'lucy', label: 'Lucy' }, | ||
{ value: 'Yiminghe', label: 'yiminghe' }, | ||
]} | ||
/> | ||
</Flex> | ||
<Flex gap={8}> | ||
<Select | ||
placeholder="Filled" | ||
variant="filled" | ||
style={{ flex: 1 }} | ||
options={[ | ||
{ value: 'jack', label: 'Jack' }, | ||
{ value: 'lucy', label: 'Lucy' }, | ||
{ value: 'Yiminghe', label: 'yiminghe' }, | ||
]} | ||
/> | ||
<Select | ||
mode="multiple" | ||
defaultValue={['lucy']} | ||
placeholder="Filled" | ||
variant="filled" | ||
style={{ flex: 1 }} | ||
options={[ | ||
{ value: 'jack', label: 'Jack' }, | ||
{ value: 'lucy', label: 'Lucy' }, | ||
{ value: 'Yiminghe', label: 'yiminghe' }, | ||
]} | ||
/> | ||
</Flex> | ||
<Flex gap={8}> | ||
<Select | ||
placeholder="Borderless" | ||
variant="borderless" | ||
style={{ flex: 1 }} | ||
options={[ | ||
{ value: 'jack', label: 'Jack' }, | ||
{ value: 'lucy', label: 'Lucy' }, | ||
{ value: 'Yiminghe', label: 'yiminghe' }, | ||
]} | ||
/> | ||
<Select | ||
mode="multiple" | ||
defaultValue={['lucy']} | ||
placeholder="Borderless" | ||
variant="borderless" | ||
style={{ flex: 1 }} | ||
options={[ | ||
{ value: 'jack', label: 'Jack' }, | ||
{ value: 'lucy', label: 'Lucy' }, | ||
{ value: 'Yiminghe', label: 'yiminghe' }, | ||
]} | ||
/> | ||
</Flex> | ||
</Flex> | ||
); | ||
|
||
export default App; |
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
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 |
---|---|---|
@@ -1,34 +1,18 @@ | ||
import type { CSSObject } from '@ant-design/cssinjs'; | ||
import type { FullToken, GenerateStyle } from 'antd/es/theme/internal'; | ||
import { genComponentStyleHook } from '../../_util/genComponentStyleHook'; | ||
import { getWeakenBorderColor } from '../../_util/getWeakenBorderColor'; | ||
|
||
export type SelectToken = FullToken<'Select'>; | ||
export type TreeSelectToken = FullToken<'TreeSelect'>; | ||
|
||
const getMultipleBorderColor = (token: SelectToken) => { | ||
const { componentCls, colorBorder } = token; | ||
return { | ||
[`${componentCls}-selection-item`]: { | ||
borderColor: getWeakenBorderColor(colorBorder), | ||
}, | ||
}; | ||
}; | ||
|
||
export const genSelectStyle: GenerateStyle<SelectToken> = (token: SelectToken): CSSObject => { | ||
const { componentCls } = token; | ||
|
||
return { | ||
[`${componentCls}`]: { | ||
['&-multiple']: getMultipleBorderColor(token), | ||
['&-multiple&-lg']: getMultipleBorderColor(token), | ||
['&-multiple&-sm']: getMultipleBorderColor(token), | ||
}, | ||
}; | ||
export const genTreeSelectStyle: GenerateStyle<TreeSelectToken> = ( | ||
token: TreeSelectToken | ||
): CSSObject => { | ||
return {}; | ||
}; | ||
|
||
export default (prefixCls: string) => { | ||
const useStyle = genComponentStyleHook('Select', (token: SelectToken) => { | ||
return [genSelectStyle(token)]; | ||
const useStyle = genComponentStyleHook('TreeSelect', (token: TreeSelectToken) => { | ||
return [genTreeSelectStyle(token)]; | ||
}); | ||
return useStyle(prefixCls); | ||
}; |