-
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): Slider color and align style
- Loading branch information
1 parent
93314a2
commit a11d983
Showing
13 changed files
with
301 additions
and
26 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 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
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 @@ | ||
import React, { useState } from 'react'; | ||
import { Slider, Switch } from '@oceanbase/design'; | ||
|
||
const App: React.FC = () => { | ||
const [disabled, setDisabled] = useState(false); | ||
|
||
const onChange = (checked: boolean) => { | ||
setDisabled(checked); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Slider defaultValue={30} disabled={disabled} /> | ||
<br /> | ||
<Slider range defaultValue={[20, 50]} disabled={disabled} /> | ||
<br /> | ||
Disabled: <Switch size="small" checked={disabled} 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,27 @@ | ||
import React from 'react'; | ||
import { Slider } from '@oceanbase/design'; | ||
import type { SliderSingleProps } from '@oceanbase/design'; | ||
|
||
const marks: SliderSingleProps['marks'] = { | ||
0: '0°C', | ||
20: '20°C', | ||
40: '40°C', | ||
60: '60°C', | ||
80: '80°C', | ||
100: { | ||
style: { | ||
color: '#f50', | ||
}, | ||
label: <strong>100°C</strong>, | ||
}, | ||
}; | ||
|
||
const App: React.FC = () => ( | ||
<> | ||
<Slider marks={marks} defaultValue={37} /> | ||
<br /> | ||
<Slider range marks={marks} defaultValue={[26, 37]} /> | ||
</> | ||
); | ||
|
||
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 React from 'react'; | ||
import { Slider, Space } from '@oceanbase/design'; | ||
import type { SliderSingleProps } from '@oceanbase/design'; | ||
|
||
const marks: SliderSingleProps['marks'] = { | ||
0: '0°C', | ||
20: '20°C', | ||
40: '40°C', | ||
60: '60°C', | ||
80: '80°C', | ||
100: { | ||
style: { | ||
color: '#f50', | ||
}, | ||
label: <strong>100°C</strong>, | ||
}, | ||
}; | ||
|
||
const App: React.FC = () => ( | ||
<Space size={70}> | ||
<Slider vertical defaultValue={30} style={{ height: 300 }} /> | ||
<Slider vertical range step={10} defaultValue={[20, 50]} style={{ height: 300 }} /> | ||
<Slider vertical range marks={marks} defaultValue={[13, 68]} style={{ height: 300 }} /> | ||
</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,20 @@ | ||
--- | ||
title: Slider 滑动输入条 | ||
nav: | ||
title: 基础组件 | ||
path: /components | ||
--- | ||
|
||
- 🔥 完全继承 antd [Slider](https://ant.design/components/slider-cn) 的能力和 API,可无缝切换。 | ||
- 💄 定制主题和样式,符合 OceanBase Design 设计规范。 | ||
|
||
## 代码演示 | ||
|
||
<!-- prettier-ignore --> | ||
<code src="./demo/basic.tsx" title="基本"></code> | ||
<code src="./demo/marks.tsx" title="带标签的滑块"></code> | ||
<code src="./demo/vertical.tsx" title="垂直方向的滑块"></code> | ||
|
||
## API | ||
|
||
- 详见 antd Slider 文档: https://ant.design/components/slider-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,31 @@ | ||
import { Slider as AntSlider } from 'antd'; | ||
import type { | ||
SliderSingleProps as AntSliderSingleProps, | ||
SliderRangeProps as AntSliderRangeProps, | ||
} from 'antd/es/slider'; | ||
import type { SliderRef } from 'rc-slider/lib/Slider'; | ||
import classNames from 'classnames'; | ||
import React, { useContext } from 'react'; | ||
import ConfigProvider from '../config-provider'; | ||
import useStyle from './style'; | ||
|
||
export * from 'antd/es/slider'; | ||
|
||
const Slider = React.forwardRef<SliderRef, AntSliderSingleProps | AntSliderRangeProps>( | ||
({ prefixCls: customizePrefixCls, className, ...restProps }, ref) => { | ||
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext); | ||
const prefixCls = getPrefixCls('slider', customizePrefixCls); | ||
const { wrapSSR } = useStyle(prefixCls); | ||
const sliderCls = classNames(className); | ||
|
||
return wrapSSR( | ||
<AntSlider ref={ref} prefixCls={customizePrefixCls} className={sliderCls} {...restProps} /> | ||
); | ||
} | ||
); | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
Slider.displayName = AntSlider.displayName; | ||
} | ||
|
||
export default Slider; |
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 type { CSSObject } from '@ant-design/cssinjs'; | ||
import type { FullToken, GenerateStyle } from 'antd/es/theme/internal'; | ||
import { genComponentStyleHook } from '../../_util/genComponentStyleHook'; | ||
|
||
export type SliderToken = FullToken<'Slider'>; | ||
|
||
export const genSliderStyle: GenerateStyle<SliderToken> = (token: SliderToken): CSSObject => { | ||
const { componentCls, dotSize = 8 } = token; | ||
return { | ||
[`${componentCls}${componentCls}-horizontal`]: { | ||
[`${componentCls}-mark`]: { | ||
[`${componentCls}-mark-text[style^="left: 0%; transform: translateX(-50%);"]`]: { | ||
transform: `translateX(calc(0% - ${dotSize / 2}px)) !important`, | ||
}, | ||
[`${componentCls}-mark-text[style^="left: 100%; transform: translateX(-50%);"]`]: { | ||
transform: `translateX(calc(-100% + ${dotSize / 2}px)) !important`, | ||
}, | ||
}, | ||
}, | ||
}; | ||
}; | ||
|
||
export default (prefixCls: string) => { | ||
const useStyle = genComponentStyleHook('Slider', token => { | ||
return [genSliderStyle(token as SliderToken)]; | ||
}); | ||
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
Oops, something went wrong.