-
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.
Merge pull request #113 from oceanbase/wangdongya-dev
feat(Tag): modify boderColor and add ellipsis for Tag
- Loading branch information
Showing
22 changed files
with
580 additions
and
4 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
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,31 @@ | ||
import { Select, Tag } from '@oceanbase/design'; | ||
import React from 'react'; | ||
|
||
const options = ['gold', 'green', 'red', 'cyan']; | ||
|
||
const tagRender = props => { | ||
const { label, value, closable, onClose } = props; | ||
const onPreventMouseDown = (event: React.MouseEvent<HTMLSpanElement>) => { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
}; | ||
return ( | ||
<Tag color={value} onMouseDown={onPreventMouseDown} closable={closable} onClose={onClose}> | ||
{label} | ||
</Tag> | ||
); | ||
}; | ||
|
||
const App: React.FC = () => ( | ||
<> | ||
<Select | ||
mode="multiple" | ||
tagRender={tagRender} | ||
defaultValue={['gold', 'cyan']} | ||
style={{ width: '100%' }} | ||
options={options.map(item => ({ label: item, value: item }))} | ||
/> | ||
</> | ||
); | ||
|
||
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,28 @@ | ||
import { Select } from '@oceanbase/design'; | ||
import React from 'react'; | ||
import type { SelectProps } from '@oceanbase/design'; | ||
|
||
const options: SelectProps['options'] = []; | ||
|
||
for (let i = 10; i < 36; i++) { | ||
options.push({ | ||
value: i.toString(36) + i, | ||
label: i.toString(36) + i, | ||
}); | ||
} | ||
|
||
const handleChange = (value: string) => { | ||
console.log(`selected ${value}`); | ||
}; | ||
|
||
const App: React.FC = () => ( | ||
<Select | ||
mode="tags" | ||
style={{ width: '100%' }} | ||
placeholder="Tags Mode" | ||
onChange={handleChange} | ||
options={options} | ||
/> | ||
); | ||
|
||
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,16 @@ | ||
--- | ||
title: Select 选择器 | ||
nav: | ||
title: 基础组件 | ||
path: /components | ||
--- | ||
|
||
- 🔥 完全兼容 antd [Select](https://ant.design/components/select-cn/) 的能力和 API,可无缝切换。 | ||
- 💄 定制主题和样式,符合 OceanBase Design 设计规范。 | ||
|
||
## 代码演示 | ||
|
||
<code src="./demo/custom-tag-render.tsx" title="自定义选择标签" description="允许自定义选择标签的样式"></code> | ||
<code src="./demo/tags.tsx" title="标签" description="tags select,随意输入的内容(scroll the menu)。"></code> | ||
|
||
- 详见 antd Select 文档: https://ant.design/components/select-cn/ |
This file was deleted.
Oops, something went wrong.
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,30 @@ | ||
import { Select as AntSelect } from 'antd'; | ||
import type { SelectProps as AntSelectProps } from 'antd/es/select'; | ||
import classNames from 'classnames'; | ||
import React, { useContext } from 'react'; | ||
import ConfigProvider from '../config-provider'; | ||
import useStyle from './style'; | ||
|
||
const { Option, OptGroup } = AntSelect; | ||
|
||
export * from 'antd/es/select'; | ||
|
||
export type SelectProps = AntSelectProps; | ||
|
||
const Select: any = ({ prefixCls: customizePrefixCls, className, ...restProps }: SelectProps) => { | ||
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext); | ||
const prefixCls = getPrefixCls('select', customizePrefixCls); | ||
const { wrapSSR } = useStyle(prefixCls); | ||
|
||
const selectCls = classNames(className); | ||
return wrapSSR(<AntSelect prefixCls={customizePrefixCls} className={selectCls} {...restProps} />); | ||
}; | ||
|
||
Select.Option = Option; | ||
Select.OptGroup = OptGroup; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
Select.displayName = AntSelect.displayName; | ||
} | ||
|
||
export default Select; |
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,24 @@ | ||
import type { CSSObject } from '@ant-design/cssinjs'; | ||
import type { FullToken, GenerateStyle } from 'antd/es/theme/internal'; | ||
import { genComponentStyleHook } from '../../_util/genComponentStyleHook'; | ||
|
||
export type SelectToken = FullToken<'Select'>; | ||
|
||
export const genSelectStyle: GenerateStyle<SelectToken> = (token: SelectToken): CSSObject => { | ||
const { componentCls } = token; | ||
|
||
return { | ||
[`${componentCls}-multiple`]: { | ||
[`${componentCls}-selection-item`]: { | ||
border: `1px solid ${token.colorBorder}66`, | ||
}, | ||
}, | ||
}; | ||
}; | ||
|
||
export default (prefixCls: string) => { | ||
const useStyle = genComponentStyleHook('Select', (token: SelectToken) => { | ||
return [genSelectStyle(token)]; | ||
}); | ||
return useStyle(prefixCls); | ||
}; |
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,28 @@ | ||
import { Tag } from '@oceanbase/design'; | ||
import React from 'react'; | ||
|
||
const log = (e: React.MouseEvent<HTMLElement>) => { | ||
console.log(e); | ||
}; | ||
|
||
const preventDefault = (e: React.MouseEvent<HTMLElement>) => { | ||
e.preventDefault(); | ||
console.log('Clicked! But prevent default.'); | ||
}; | ||
|
||
const App: React.FC = () => ( | ||
<> | ||
<Tag>Tag 1</Tag> | ||
<Tag> | ||
<a href="https://github.com/oceanbase/oceanbase-design">Link</a> | ||
</Tag> | ||
<Tag closable onClose={log}> | ||
Tag 2 | ||
</Tag> | ||
<Tag closable onClose={preventDefault}> | ||
Prevent Default | ||
</Tag> | ||
</> | ||
); | ||
|
||
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,69 @@ | ||
import React from 'react'; | ||
import { Divider, Space, Tag } from '@oceanbase/design'; | ||
|
||
const App: React.FC = () => { | ||
return ( | ||
<> | ||
<Space size={[0, 'small']} wrap> | ||
<Tag bordered={false}>Tag 1</Tag> | ||
<Tag bordered={false}>Tag 2</Tag> | ||
<Tag bordered={false} closable> | ||
Tag 3 | ||
</Tag> | ||
<Tag bordered={false} closable> | ||
Tag 4 | ||
</Tag> | ||
</Space> | ||
<Divider /> | ||
<Space size={[0, 'small']} wrap> | ||
<Tag bordered={false} color="processing"> | ||
processing | ||
</Tag> | ||
<Tag bordered={false} color="success"> | ||
success | ||
</Tag> | ||
<Tag bordered={false} color="error"> | ||
error | ||
</Tag> | ||
<Tag bordered={false} color="warning"> | ||
warning | ||
</Tag> | ||
<Tag bordered={false} color="magenta"> | ||
magenta | ||
</Tag> | ||
<Tag bordered={false} color="red"> | ||
red | ||
</Tag> | ||
<Tag bordered={false} color="volcano"> | ||
volcano | ||
</Tag> | ||
<Tag bordered={false} color="orange"> | ||
orange | ||
</Tag> | ||
<Tag bordered={false} color="gold"> | ||
gold | ||
</Tag> | ||
<Tag bordered={false} color="lime"> | ||
lime | ||
</Tag> | ||
<Tag bordered={false} color="green"> | ||
green | ||
</Tag> | ||
<Tag bordered={false} color="cyan"> | ||
cyan | ||
</Tag> | ||
<Tag bordered={false} color="blue"> | ||
blue | ||
</Tag> | ||
<Tag bordered={false} color="geekblue"> | ||
geekblue | ||
</Tag> | ||
<Tag bordered={false} color="purple"> | ||
purple | ||
</Tag> | ||
</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,33 @@ | ||
import { Tag } from '@oceanbase/design'; | ||
import React, { useState } from 'react'; | ||
|
||
const { CheckableTag } = Tag; | ||
|
||
const tagsData = ['Movies', 'Books', 'Music', 'Sports']; | ||
|
||
const App: React.FC = () => { | ||
const [selectedTags, setSelectedTags] = useState<string[]>(['Books']); | ||
|
||
const handleChange = (tag: string, checked: boolean) => { | ||
const nextSelectedTags = checked ? [...selectedTags, tag] : selectedTags.filter(t => t !== tag); | ||
console.log('You are interested in: ', nextSelectedTags); | ||
setSelectedTags(nextSelectedTags); | ||
}; | ||
|
||
return ( | ||
<> | ||
<span style={{ marginRight: 8 }}>Categories:</span> | ||
{tagsData.map(tag => ( | ||
<CheckableTag | ||
key={tag} | ||
checked={selectedTags.indexOf(tag) > -1} | ||
onChange={checked => handleChange(tag, checked)} | ||
> | ||
{tag} | ||
</CheckableTag> | ||
))} | ||
</> | ||
); | ||
}; | ||
|
||
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,30 @@ | ||
import { Tag, Divider } from '@oceanbase/design'; | ||
import React from 'react'; | ||
|
||
const App: React.FC = () => ( | ||
<> | ||
<Divider orientation="left">Presets</Divider> | ||
<div> | ||
<Tag color="magenta">magenta</Tag> | ||
<Tag color="red">red</Tag> | ||
<Tag color="volcano">volcano</Tag> | ||
<Tag color="orange">orange</Tag> | ||
<Tag color="gold">gold</Tag> | ||
<Tag color="lime">lime</Tag> | ||
<Tag color="green">green</Tag> | ||
<Tag color="cyan">cyan</Tag> | ||
<Tag color="blue">blue</Tag> | ||
<Tag color="geekblue">geekblue</Tag> | ||
<Tag color="purple">purple</Tag> | ||
</div> | ||
<Divider orientation="left">Custom</Divider> | ||
<div> | ||
<Tag color="#f50">#f50</Tag> | ||
<Tag color="#2db7f5">#2db7f5</Tag> | ||
<Tag color="#87d068">#87d068</Tag> | ||
<Tag color="#108ee9">#108ee9</Tag> | ||
</div> | ||
</> | ||
); | ||
|
||
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,15 @@ | ||
import { Tag } from '@oceanbase/design'; | ||
import React from 'react'; | ||
|
||
const App: React.FC = () => ( | ||
<> | ||
<Tag> | ||
Show ellipsis for excess.Show ellipsis for excess.Show ellipsis for excess.Show ellipsis for | ||
excess.Show ellipsis for excess.Show ellipsis for excess.Show ellipsis for excess.Show | ||
ellipsis for excess.Show ellipsis for excess.Show ellipsis for excess.Show ellipsis for | ||
excess.Show ellipsis for excess.Show ellipsis for excess.Show ellipsis for excess. | ||
</Tag> | ||
</> | ||
); | ||
|
||
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,27 @@ | ||
import { | ||
FacebookOutlined, | ||
LinkedinOutlined, | ||
TwitterOutlined, | ||
YoutubeOutlined, | ||
} from '@oceanbase/icons'; | ||
import { Tag } from '@oceanbase/design'; | ||
import React from 'react'; | ||
|
||
const App: React.FC = () => ( | ||
<> | ||
<Tag icon={<TwitterOutlined />} color="#55acee"> | ||
</Tag> | ||
<Tag icon={<YoutubeOutlined />} color="#cd201f"> | ||
Youtube | ||
</Tag> | ||
<Tag icon={<FacebookOutlined />} color="#3b5999"> | ||
</Tag> | ||
<Tag icon={<LinkedinOutlined />} color="#55acee"> | ||
</Tag> | ||
</> | ||
); | ||
|
||
export default App; |
Oops, something went wrong.