mirror of
https://github.com/apache/superset.git
synced 2026-04-23 18:14:56 +00:00
refactor(Switch): Upgrade Switch to Ant Design 5 (#30731)
This commit is contained in:
@@ -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 = {
|
||||
|
||||
41
superset-frontend/src/components/Switch/Switch.test.tsx
Normal file
41
superset-frontend/src/components/Switch/Switch.test.tsx
Normal 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();
|
||||
});
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user