-
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(design): vertical align center => baseline for over length Ch…
…eckbox
- Loading branch information
1 parent
126d0e3
commit 765b7a2
Showing
10 changed files
with
166 additions
and
1 deletion.
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,14 @@ | ||
import React from 'react'; | ||
import { Checkbox } from '@oceanbase/design'; | ||
|
||
const App: React.FC = () => ( | ||
<Checkbox | ||
onChange={e => { | ||
console.log(`checked: ${e.target.checked}`); | ||
}} | ||
> | ||
Checkbox | ||
</Checkbox> | ||
); | ||
|
||
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,35 @@ | ||
import React from 'react'; | ||
import { Checkbox } from '@oceanbase/design'; | ||
import type { CheckboxGroupProps } from '@oceanbase/design/es/checkbox'; | ||
|
||
const onChange: CheckboxGroupProps['onChange'] = checkedValues => { | ||
console.log('checked = ', checkedValues); | ||
}; | ||
|
||
const options = [ | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Pear', value: 'Pear' }, | ||
{ label: 'Orange', value: 'Orange' }, | ||
]; | ||
|
||
const optionsWithDisabled = [ | ||
{ label: 'Apple', value: 'Apple' }, | ||
{ label: 'Pear', value: 'Pear' }, | ||
{ label: 'Orange', value: 'Orange', disabled: false }, | ||
]; | ||
|
||
const App: React.FC = () => ( | ||
<> | ||
<Checkbox.Group options={options} defaultValue={['Pear']} onChange={onChange} /> | ||
<br /> | ||
<br /> | ||
<Checkbox.Group | ||
options={optionsWithDisabled} | ||
disabled | ||
defaultValue={['Apple']} | ||
onChange={onChange} | ||
/> | ||
</> | ||
); | ||
|
||
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,26 @@ | ||
import React, { useState } from 'react'; | ||
import { Checkbox, Space } from '@oceanbase/design'; | ||
import type { CheckboxGroupProps } from '@oceanbase/design/es/checkbox'; | ||
|
||
const App: React.FC = () => { | ||
const [value, setValue] = useState(['long']); | ||
|
||
const onChange: CheckboxGroupProps['onChange'] = value => { | ||
console.log('checkbox checked', value); | ||
setValue(value); | ||
}; | ||
|
||
return ( | ||
<Checkbox.Group onChange={onChange} value={value}> | ||
<Space direction="vertical"> | ||
<Checkbox value="long"> | ||
This is long long long long long long long long long long long long long long long long | ||
long long long long long long long long text | ||
</Checkbox> | ||
<Checkbox value="short">This is short text</Checkbox> | ||
</Space> | ||
</Checkbox.Group> | ||
); | ||
}; | ||
|
||
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,22 @@ | ||
--- | ||
title: Checkbox 多选框 | ||
nav: | ||
title: 基础组件 | ||
path: /components | ||
demo: | ||
cols: 2 | ||
--- | ||
|
||
- 🔥 完全继承 antd [Checkbox](https://ant.design/components/checkbox-cn) 的能力和 API,可无缝切换。 | ||
- 💄 定制主题和样式,符合 OceanBase Design 设计规范。 | ||
|
||
## 代码演示 | ||
|
||
<!-- prettier-ignore --> | ||
<code src="./demo/basic.tsx" title="基本"></code> | ||
<code src="./demo/group.tsx" title="Checkbox 组"></code> | ||
<code src="./demo/over-length.tsx" title="超长内容"></code> | ||
|
||
## API | ||
|
||
- 详见 antd Checkbox 文档: https://ant.design/components/checkbox-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,38 @@ | ||
import { Checkbox as AntCheckbox } from 'antd'; | ||
import type { CheckboxProps as AntCheckboxProps, CheckboxRef } from 'antd/es/Checkbox'; | ||
import classNames from 'classnames'; | ||
import React, { useContext } from 'react'; | ||
import ConfigProvider from '../config-provider'; | ||
import useStyle from './style'; | ||
|
||
export * from 'antd/es/checkbox'; | ||
|
||
const InternalCheckbox = React.forwardRef<CheckboxRef, AntCheckboxProps>( | ||
({ prefixCls: customizePrefixCls, className, ...restProps }, ref) => { | ||
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext); | ||
const prefixCls = getPrefixCls('checkbox', customizePrefixCls); | ||
const { wrapSSR } = useStyle(prefixCls); | ||
const checkboxCls = classNames(className); | ||
|
||
return wrapSSR( | ||
<AntCheckbox | ||
ref={ref} | ||
prefixCls={customizePrefixCls} | ||
className={checkboxCls} | ||
{...restProps} | ||
/> | ||
); | ||
} | ||
); | ||
|
||
const Checkbox = InternalCheckbox as typeof Checkbox; | ||
|
||
Checkbox.Group = AntCheckbox.Group; | ||
// @ts-ignore | ||
Checkbox.__ANT_CHECKBOX = AntCheckbox.__ANT_CHECKBOX; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
Checkbox.displayName = AntCheckbox.displayName; | ||
} | ||
|
||
export default Checkbox; |
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 @@ | ||
export * from 'antd/es/radio/interface'; |
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,26 @@ | ||
import type { CSSObject } from '@ant-design/cssinjs'; | ||
import type { FullToken, GenerateStyle } from 'antd/es/theme/internal'; | ||
import { genComponentStyleHook } from '../../_util/genComponentStyleHook'; | ||
|
||
export type CheckboxToken = FullToken<'Checkbox'>; | ||
|
||
export const genCheckboxStyle: GenerateStyle<CheckboxToken> = (token: CheckboxToken): CSSObject => { | ||
const { componentCls, fontSize, fontSizeLG, lineHeight } = token; | ||
return { | ||
[`${componentCls}-wrapper`]: { | ||
[`${componentCls}`]: { | ||
alignSelf: 'baseline', | ||
[`${componentCls}-inner`]: { | ||
transform: `translate(0px, ${(fontSize * lineHeight - fontSizeLG) / 2}px)`, | ||
}, | ||
}, | ||
}, | ||
}; | ||
}; | ||
|
||
export default (prefixCls: string) => { | ||
const useStyle = genComponentStyleHook('Checkbox', token => { | ||
return [genCheckboxStyle(token as CheckboxToken)]; | ||
}); | ||
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