-
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): Switch unchecked background color
- Loading branch information
1 parent
ee829f7
commit ef16661
Showing
7 changed files
with
75 additions
and
2 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
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; |
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
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; |
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 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); | ||
}; |