Skip to content

Commit

Permalink
improve(design): Slider color and align style
Browse files Browse the repository at this point in the history
  • Loading branch information
dengfuping committed Nov 10, 2024
1 parent 93314a2 commit a11d983
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 26 deletions.
1 change: 1 addition & 0 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default defineConfig({
{ title: 'Switch 开关', link: '/components/switch' },
{ title: 'Select 选择器', link: '/components/select' },
{ title: 'TreeSelect 树选择', link: '/components/tree-select' },
{ title: 'Slider 滑动输入条', link: '/components/slider' },
],
},
{
Expand Down
1 change: 1 addition & 0 deletions packages/design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@babel/preset-env": "^7.26.0",
"antd-token-previewer": "^2.0.8",
"rc-select": "^14.16.2",
"rc-slider": "^11.1.7",
"rc-table": "^7.48.1",
"rc-tree-select": "^5.24.3"
},
Expand Down
1 change: 0 additions & 1 deletion packages/design/src/checkbox/interface.ts

This file was deleted.

3 changes: 3 additions & 0 deletions packages/design/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ export type { SelectProps } from './select';
export { default as TreeSelect } from './tree-select';
export type { TreeSelectProps } from './tree-select';

export { default as Slider } from './slider';
export type { SliderSingleProps, SliderRangeProps } from './slider';

export { default as Tooltip } from './tooltip';
export type { TooltipProps } from './tooltip';

Expand Down
22 changes: 22 additions & 0 deletions packages/design/src/slider/demo/basic.tsx
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;
27 changes: 27 additions & 0 deletions packages/design/src/slider/demo/marks.tsx
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;
27 changes: 27 additions & 0 deletions packages/design/src/slider/demo/vertical.tsx
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;
20 changes: 20 additions & 0 deletions packages/design/src/slider/index.md
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
1 change: 0 additions & 1 deletion packages/design/src/slider/index.ts

This file was deleted.

31 changes: 31 additions & 0 deletions packages/design/src/slider/index.tsx
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;
28 changes: 28 additions & 0 deletions packages/design/src/slider/style/index.ts
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);
};
8 changes: 8 additions & 0 deletions packages/design/src/theme/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ const defaultTheme: ThemeConfig = {
multipleItemBorderColor: tagColorBorder,
multipleItemBorderColorDisabled: tagColorBorder,
},
Slider: {
trackBg: '#006AFF',
trackHoverBg: '#5189fb',
trackBgDisabled: '#b3ccff',
handleColor: '#006AFF',
handleActiveColor: '#5189fb',
handleColorDisabled: '#b3ccff',
},
Tag: {
defaultColor: '#5c6b8a',
colorBorder: tagColorBorder,
Expand Down
Loading

0 comments on commit a11d983

Please sign in to comment.