Skip to content

feat: switch #2712

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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"homepage": "/dashboard",
"dependencies": {
"@devtron-labs/devtron-fe-common-lib": "1.13.0-pre-6",
"@devtron-labs/devtron-fe-common-lib": "1.13.0-beta-8",
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
"@rjsf/core": "^5.13.3",
"@rjsf/utils": "^5.13.3",
Expand Down
4 changes: 4 additions & 0 deletions src/css/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2863,6 +2863,10 @@ button.anchor {
width: 10px;
}

.w-12 {
width: 12px;
}

.w-14 {
width: 14px;
}
Expand Down
128 changes: 128 additions & 0 deletions src/stories/Switch.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (c) 2024. Devtron Inc.
*
* Licensed 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 { useState } from 'react'
import type { Meta, StoryObj } from '@storybook/react'

import {
ComponentSizeType,
DTSwitch,

Check failure on line 22 in src/stories/Switch.stories.tsx

View workflow job for this annotation

GitHub Actions / ci

'"@devtron-labs/devtron-fe-common-lib"' has no exported member named 'DTSwitch'. Did you mean 'Switch'?
DTSwitchProps,

Check failure on line 23 in src/stories/Switch.stories.tsx

View workflow job for this annotation

GitHub Actions / ci

'"@devtron-labs/devtron-fe-common-lib"' has no exported member named 'DTSwitchProps'. Did you mean 'SwitchProps'?
iconMap,
SWITCH_VARIANTS,
} from '@devtron-labs/devtron-fe-common-lib'

type BaseComponentPropsType = Omit<DTSwitchProps, 'onChange' | 'isChecked'>

const BaseComponent = (props: BaseComponentPropsType) => {
const [isChecked, setIsChecked] = useState<boolean>(false)

const handleChange = () => {
setIsChecked((prev) => !prev)
}

const switchProps = {
...props,
isChecked,
onChange: handleChange,
} as DTSwitchProps

return <DTSwitch {...switchProps} />
}

const meta = {
component: BaseComponent,
argTypes: {
variant: {
options: Object.keys(SWITCH_VARIANTS) as Array<keyof typeof SWITCH_VARIANTS>,
control: { type: 'radio' },
},
iconName: {
options: [null, ...Object.keys(iconMap)],
control: { type: 'select' },
},
iconColor: {
control: { type: 'text' },
},
indeterminate: {
options: [true, false],
control: { type: 'radio' },
},
size: {
options: [ComponentSizeType.medium, ComponentSizeType.small],
control: { type: 'radio' },
},
isDisabled: {
options: [true, false],
control: { type: 'radio' },
},
isLoading: {
options: [true, false],
control: { type: 'radio' },
},
tooltipContent: {
control: { type: 'text' },
},
},
} satisfies Meta<BaseComponentPropsType>

type Story = StoryObj<typeof meta>

const COMMON_SWITCH_TEMPLATE: Story = {
args: {
name: 'switch-story',
dataTestId: 'switch-story',
variant: 'positive',
size: ComponentSizeType.medium,
isDisabled: false,
isLoading: false,
tooltipContent: '',
ariaLabel: 'Toggle',
},
}

export const RoundedSwitch: Story = {
...COMMON_SWITCH_TEMPLATE,
argTypes: {
...meta.argTypes,
iconName: {
options: [null],
control: { type: 'select' },
},
},
args: {
...COMMON_SWITCH_TEMPLATE.args,
shape: 'rounded',
} satisfies BaseComponentPropsType,
}

export const SquareSwitch: Story = {
...COMMON_SWITCH_TEMPLATE,
argTypes: {
...meta.argTypes,
indeterminate: {
options: [false],
control: { type: 'radio' },
},
},
args: {
...COMMON_SWITCH_TEMPLATE.args,
shape: 'square',
iconName: 'ic-check',
} satisfies BaseComponentPropsType,
}

export default meta
Loading
Loading