-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(common):[components] add WToggleSwitchRounded (#299)
Co-authored-by: Tushar98644 <[email protected]> Co-authored-by: Anindya Kundu <[email protected]>
- Loading branch information
1 parent
1dde8f5
commit 2d5b05a
Showing
4 changed files
with
104 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@import '@/common/scss/colors.scss'; | ||
@import '@/common/scss/sizes.scss'; | ||
|
||
.w-toggle-r { | ||
width: 40px; | ||
height: 24px; | ||
padding: 2px; | ||
border-radius: 20px; | ||
background-color: $c-bg-white; | ||
cursor: pointer; | ||
|
||
.w-toggle-r-track { | ||
position: relative; | ||
width: 100%; | ||
height: 100%; | ||
border-radius: 18px; | ||
box-shadow: inset 0px 0px 4px $c-shadow; | ||
background-color: $c-bg-grey; | ||
transition: background-color 0.5s ease; | ||
|
||
.w-toggle-r-handle { | ||
position: absolute; | ||
top: 2px; | ||
left: 2px; | ||
width: 16px; | ||
height: 16px; | ||
border-radius: 8px; | ||
box-shadow: 0px 0px 4px $c-shadow; | ||
background-color: $c-bg-white; | ||
transition: left 0.25s ease; | ||
} | ||
} | ||
|
||
&.w-toggle-r-active { | ||
.w-toggle-r-track { | ||
background-color: $mb-accent; | ||
|
||
.w-toggle-r-handle { | ||
left: calc(100% - 18px); | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/common/components/WToggleSwitchRounded/index.stories.tsx
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,32 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { linkTo } from '@storybook/addon-links'; | ||
import { WToggleSwitchRounded } from '..'; | ||
|
||
// ------------------------------------------------------------------------------------------------- | ||
|
||
export default { | ||
title: 'Common/WToggleSwitchRounded', | ||
component: WToggleSwitchRounded, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
} as Meta<typeof WToggleSwitchRounded>; | ||
|
||
type Story = StoryObj<typeof WToggleSwitchRounded>; | ||
|
||
// ------------------------------------------------------------------------------------------------- | ||
|
||
export const Active: Story = { | ||
args: { | ||
active: true, | ||
handlerClick: linkTo('Common/WToggleSwitchRounded', 'Inactive'), | ||
}, | ||
}; | ||
|
||
export const Inactive: Story = { | ||
args: { | ||
active: false, | ||
handlerClick: linkTo('Common/WToggleSwitchRounded', 'Active'), | ||
}, | ||
}; |
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,28 @@ | ||
// -- stylesheet ----------------------------------------------------------------------------------- | ||
|
||
import './index.scss'; | ||
|
||
// -- component definition ------------------------------------------------------------------------- | ||
|
||
/** | ||
* React component definition for Toggle Switch widget. | ||
*/ | ||
export default function Toggle(props: { | ||
/** Whether state is `on` (active) or `off`. */ | ||
active: boolean; | ||
/** Callback function for click event. */ | ||
handlerClick: CallableFunction; | ||
}): JSX.Element { | ||
// --------------------------------------------------------------------------- | ||
|
||
return ( | ||
<div | ||
className={`w-toggle-r ${props.active ? 'w-toggle-r-active' : ''}`} | ||
onClick={() => props.handlerClick()} | ||
> | ||
<div className="w-toggle-r-track"> | ||
<div className="w-toggle-r-handle"></div> | ||
</div> | ||
</div> | ||
); | ||
} |
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