refactor(Switch): Upgrade Switch to Ant Design 5 (#30731)
This commit is contained in:
parent
9bb69ab311
commit
bc5da631c8
|
|
@ -56,7 +56,8 @@ import Mousetrap from 'mousetrap';
|
|||
import Button from 'src/components/Button';
|
||||
import Timer from 'src/components/Timer';
|
||||
import ResizableSidebar from 'src/components/ResizableSidebar';
|
||||
import { AntdDropdown, AntdSwitch, Skeleton } from 'src/components';
|
||||
import { AntdDropdown, Skeleton } from 'src/components';
|
||||
import { Switch } from 'src/components/Switch';
|
||||
import { Input } from 'src/components/Input';
|
||||
import { Menu } from 'src/components/Menu';
|
||||
import Icons from 'src/components/Icons';
|
||||
|
|
@ -698,7 +699,7 @@ const SqlEditor: FC<Props> = ({
|
|||
<Menu.Item css={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||
{' '}
|
||||
<span>{t('Render HTML')}</span>{' '}
|
||||
<AntdSwitch
|
||||
<Switch
|
||||
checked={renderHTMLEnabled}
|
||||
onChange={handleToggleRenderHTMLEnabled}
|
||||
/>{' '}
|
||||
|
|
@ -706,7 +707,7 @@ const SqlEditor: FC<Props> = ({
|
|||
<Menu.Item css={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||
{' '}
|
||||
<span>{t('Autocomplete')}</span>{' '}
|
||||
<AntdSwitch
|
||||
<Switch
|
||||
checked={autocompleteEnabled}
|
||||
onChange={handleToggleAutocompleteEnabled}
|
||||
/>{' '}
|
||||
|
|
|
|||
|
|
@ -33,12 +33,15 @@ export const InteractiveSwitch = ({ checked, ...rest }: SwitchProps) => {
|
|||
/>
|
||||
);
|
||||
};
|
||||
const defaultCheckedValue = true;
|
||||
|
||||
InteractiveSwitch.args = {
|
||||
checked: false,
|
||||
checked: defaultCheckedValue,
|
||||
disabled: false,
|
||||
loading: false,
|
||||
title: 'Switch',
|
||||
defaultChecked: defaultCheckedValue,
|
||||
autoFocus: true,
|
||||
};
|
||||
|
||||
InteractiveSwitch.argTypes = {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { render, screen } from 'spec/helpers/testing-library';
|
||||
import { Switch } from '.';
|
||||
|
||||
const mockedProps = {
|
||||
label: 'testLabel',
|
||||
dataTest: 'dataTest',
|
||||
checked: false,
|
||||
};
|
||||
|
||||
test('should render', () => {
|
||||
const { container } = render(<Switch {...mockedProps} />);
|
||||
expect(container).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('should have the correct checked prop', () => {
|
||||
render(<Switch {...mockedProps} />);
|
||||
|
||||
const switchElement = screen.getByRole('switch');
|
||||
|
||||
expect(switchElement).toBeInTheDocument();
|
||||
expect(switchElement).not.toBeChecked();
|
||||
});
|
||||
|
|
@ -16,14 +16,8 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { styled } from '@superset-ui/core';
|
||||
import BaseSwitch, { SwitchProps } from 'antd/lib/switch';
|
||||
import { SwitchProps } from 'antd-v5/lib/switch';
|
||||
import { Switch as AntdSwitch } from 'antd-v5';
|
||||
|
||||
const StyledSwitch = styled(BaseSwitch)`
|
||||
.ant-switch-checked {
|
||||
background-color: ${({ theme }) => theme.colors.primary.base};
|
||||
}
|
||||
`;
|
||||
|
||||
export const Switch = (props: SwitchProps) => <StyledSwitch {...props} />;
|
||||
export const Switch = (props: SwitchProps) => <AntdSwitch {...props} />;
|
||||
export type { SwitchProps };
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ export {
|
|||
Modal as AntdModal,
|
||||
Select as AntdSelect,
|
||||
Slider as AntdSlider,
|
||||
Switch as AntdSwitch,
|
||||
Tabs as AntdTabs,
|
||||
Tooltip as AntdTooltip,
|
||||
} from 'antd';
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
import { SupersetTheme, t } from '@superset-ui/core';
|
||||
import { AntdSwitch } from 'src/components';
|
||||
import { Switch } from 'src/components/Switch';
|
||||
import InfoTooltip from 'src/components/InfoTooltip';
|
||||
import ValidatedInput from 'src/components/Form/LabeledErrorBoundInput';
|
||||
import { FieldPropTypes } from '../../types';
|
||||
|
|
@ -296,7 +296,7 @@ export const forceSSLField = ({
|
|||
sslForced,
|
||||
}: FieldPropTypes) => (
|
||||
<div css={(theme: SupersetTheme) => infoTooltip(theme)}>
|
||||
<AntdSwitch
|
||||
<Switch
|
||||
disabled={sslForced && !isEditMode}
|
||||
checked={db?.parameters?.encryption || sslForced}
|
||||
onChange={changed => {
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ jest.mock('@superset-ui/core', () => ({
|
|||
isFeatureEnabled: jest.fn().mockReturnValue(true),
|
||||
}));
|
||||
|
||||
jest.mock('src/components', () => ({
|
||||
AntdSwitch: ({
|
||||
jest.mock('src/components/Switch', () => ({
|
||||
Switch: ({
|
||||
checked,
|
||||
onChange,
|
||||
}: {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import {
|
|||
isFeatureEnabled,
|
||||
FeatureFlag,
|
||||
} from '@superset-ui/core';
|
||||
import { AntdSwitch } from 'src/components';
|
||||
import { Switch } from 'src/components/Switch';
|
||||
import InfoTooltip from 'src/components/InfoTooltip';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { infoTooltip, toggleStyle } from './styles';
|
||||
|
|
@ -80,7 +80,7 @@ const SSHTunnelSwitch = ({
|
|||
|
||||
return isSSHTunnelEnabled ? (
|
||||
<div css={(theme: SupersetTheme) => infoTooltip(theme)}>
|
||||
<AntdSwitch
|
||||
<Switch
|
||||
checked={isChecked}
|
||||
onChange={handleOnChange}
|
||||
data-test="ssh-tunnel-switch"
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ import {
|
|||
loadingCardCount,
|
||||
mq,
|
||||
} from 'src/views/CRUD/utils';
|
||||
import { AntdSwitch } from 'src/components';
|
||||
import { Switch } from 'src/components/Switch';
|
||||
import getBootstrapData from 'src/utils/getBootstrapData';
|
||||
import { TableTab } from 'src/views/CRUD/types';
|
||||
import SubMenu, { SubMenuProps } from 'src/features/home/SubMenu';
|
||||
|
|
@ -340,7 +340,7 @@ function Welcome({ user, addDangerToast }: WelcomeProps) {
|
|||
name: (
|
||||
<WelcomeNav>
|
||||
<div className="switch">
|
||||
<AntdSwitch checked={checked} onClick={handleToggle} />
|
||||
<Switch checked={checked} onClick={handleToggle} />
|
||||
<span>{t('Thumbnails')}</span>
|
||||
</div>
|
||||
</WelcomeNav>
|
||||
|
|
|
|||
|
|
@ -75,6 +75,10 @@ const baseConfig: ThemeConfig = {
|
|||
handleSizeHover: 10,
|
||||
handleLineWidthHover: 2,
|
||||
},
|
||||
Switch: {
|
||||
colorPrimaryHover: supersetTheme.colors.primary.base,
|
||||
colorTextTertiary: supersetTheme.colors.grayscale.light1,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue