refactor(Switch): Upgrade Switch to Ant Design 5 (#30731)

This commit is contained in:
alexandrusoare
2024-10-30 20:18:49 +02:00
committed by GitHub
parent 9bb69ab311
commit bc5da631c8
10 changed files with 64 additions and 22 deletions

View File

@@ -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 = {

View File

@@ -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();
});

View File

@@ -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 };