Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve(design): Switch unchecked background color #833

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/design/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export type { RadioProps } from './radio';
export { default as Checkbox } from './checkbox';
export type { CheckboxProps } from './checkbox';

export { default as Switch } from './switch';
export type { SwitchProps } from './switch';

export { default as Select } from './select';
export type { SelectProps } from './select';

Expand Down
2 changes: 1 addition & 1 deletion packages/design/src/radio/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const InternalRadio = React.forwardRef<RadioRef, AntRadioProps>(
}
);

const Radio = InternalRadio as typeof Radio;
const Radio = InternalRadio as typeof AntRadio;

Radio.Button = AntRadio.Button;
Radio.Group = AntRadio.Group;
Expand Down
17 changes: 17 additions & 0 deletions packages/design/src/switch/demo/text.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { CheckOutlined, CloseOutlined } from '@ant-design/icons';
import { Space, Switch } from '@oceanbase/design';

const App: React.FC = () => (
<Space direction="vertical">
<Switch checkedChildren="ๅผ€ๅฏ" unCheckedChildren="ๅ…ณ้—ญ" defaultChecked />
<Switch checkedChildren="1" unCheckedChildren="0" />
<Switch
checkedChildren={<CheckOutlined />}
unCheckedChildren={<CloseOutlined />}
defaultChecked
/>
</Space>
);

export default App;
1 change: 1 addition & 0 deletions packages/design/src/switch/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ demo:
<code src="./demo/size.tsx" title="ๅคงๅฐ"></code>
<code src="./demo/disabled.tsx" title="็ฆ็”จ"></code>
<code src="./demo/loading.tsx" title="ๅŠ ่ฝฝไธญ"></code>
<code src="./demo/text.tsx" title="ๆ–‡ๅญ—ๅ’Œๅ›พๆ ‡"></code>

## API

Expand Down
1 change: 0 additions & 1 deletion packages/design/src/switch/index.ts

This file was deleted.

31 changes: 31 additions & 0 deletions packages/design/src/switch/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Switch as AntSwitch } from 'antd';
import type { SwitchProps as AntSwitchProps } from 'antd/es/switch';
import classNames from 'classnames';
import React, { useContext } from 'react';
import ConfigProvider from '../config-provider';
import useStyle from './style';

export * from 'antd/es/switch';

const InternalSwitch = React.forwardRef<HTMLButtonElement, AntSwitchProps>(
({ prefixCls: customizePrefixCls, className, ...restProps }, ref) => {
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
const prefixCls = getPrefixCls('switch', customizePrefixCls);
const { wrapSSR } = useStyle(prefixCls);
const switchCls = classNames(className);
return wrapSSR(
<AntSwitch ref={ref} prefixCls={customizePrefixCls} className={switchCls} {...restProps} />
);
}
);

const Switch = InternalSwitch as typeof AntSwitch;

// @ts-ignore
Switch.__ANT_SWITCH = AntSwitch.__ANT_SWITCH;

if (process.env.NODE_ENV !== 'production') {
Switch.displayName = AntSwitch.displayName;
}

export default Switch;
22 changes: 22 additions & 0 deletions packages/design/src/switch/style/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { CSSObject } from '@ant-design/cssinjs';
import type { FullToken, GenerateStyle } from 'antd/es/theme/internal';
import { genComponentStyleHook } from '../../_util/genComponentStyleHook';

export type SwitchToken = FullToken<'Switch'>;

export const genSwitchStyle: GenerateStyle<SwitchToken> = (token: SwitchToken): CSSObject => {
const { componentCls } = token;
return {
[`${componentCls}:not(${componentCls}-checked):not(${componentCls}-disabled):not(${componentCls}-loading)`]:
{
background: token.colorTextTertiary,
},
};
};

export default (prefixCls: string) => {
const useStyle = genComponentStyleHook('Switch', token => {
return [genSwitchStyle(token as SwitchToken)];
});
return useStyle(prefixCls);
};
Loading