-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using bento css. added different stories and mixins.
- Loading branch information
1 parent
3785756
commit 3970ca5
Showing
6 changed files
with
264 additions
and
69 deletions.
There are no files selected for viewing
193 changes: 144 additions & 49 deletions
193
packages/lib/src/components/internal/Toggle/Toggle.scss
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 |
---|---|---|
@@ -1,64 +1,159 @@ | ||
@use 'styles/mixins'; | ||
@import 'styles/variable-generator'; | ||
|
||
.adyen-checkout-toggle { | ||
$component-root: &; | ||
$label-padding: token(toggle-label-padding); | ||
|
||
color: inherit; | ||
cursor: pointer; | ||
display: flex; | ||
user-select: none; | ||
width: auto; | ||
} | ||
|
||
.adyen-checkout-toggle--label-first { | ||
align-items: flex-start; | ||
flex-direction: row-reverse; | ||
justify-content: flex-end; | ||
} | ||
@include mixins.box-sizing-setter(true); | ||
|
||
.adyen-checkout-toggle__input { | ||
cursor: inherit; | ||
opacity: 0; | ||
position: absolute; | ||
} | ||
&--disabled { | ||
cursor: not-allowed; | ||
display: flex; | ||
} | ||
|
||
.adyen-checkout-toggle__input:checked+.adyen-checkout-toggle__track { | ||
background-color: #00112c; | ||
border: 0; | ||
padding: 2px; | ||
} | ||
&--readonly { | ||
pointer-events: none; | ||
} | ||
|
||
.adyen-checkout-toggle__track { | ||
align-items: center; | ||
background-color: #fff; | ||
border: 1px solid #8d95a3; | ||
border-radius: 12px; | ||
display: flex; | ||
height: 20px; | ||
min-width: 36px; | ||
padding: 2px 4px; | ||
position: relative; | ||
} | ||
&--label-first { | ||
align-items: flex-start; | ||
flex-direction: row-reverse; | ||
justify-content: flex-end; | ||
} | ||
|
||
.adyen-checkout-toggle__handle { | ||
align-content: center; | ||
background-color: #00112c; | ||
border-radius: 12px; | ||
color: #00112c; | ||
display: inline-flex; | ||
height: 12px; | ||
justify-content: center; | ||
transition: transform .15s cubic-bezier(.2, 0, .4, .9); | ||
width: 12px; | ||
} | ||
&__input { | ||
cursor: inherit; | ||
opacity: 0; | ||
position: absolute; | ||
} | ||
|
||
.adyen-checkout-toggle__input:checked+* .adyen-checkout-toggle__handle { | ||
background-color: #fff; | ||
height: 16px; | ||
transform: translate(100%); | ||
width: 16px; | ||
} | ||
&__track { | ||
align-items: center; | ||
background-color: token(toggle-track-background-color); | ||
border: token(toggle-track-border); | ||
border-radius: token(toggle-track-border-radius); | ||
display: flex; | ||
height: token(toggle-track-height); | ||
min-width: token(toggle-track-width); | ||
padding: token(toggle-track-padding); | ||
position: relative; | ||
|
||
#{$component-root}__input:focus-visible + & { | ||
@include mixins.b-focus-ring; | ||
} | ||
|
||
#{$component-root}__input:hover:enabled + & { | ||
background-color: token(toggle-track-hover-background-color); | ||
border-color: token(toggle-track-hover-border-color); | ||
} | ||
|
||
#{$component-root}__input:active:enabled + & { | ||
background-color: token(toggle-track-active-background-color); | ||
border-color: token(toggle-track-active-border-color); | ||
} | ||
|
||
#{$component-root}__input:disabled + & { | ||
background-color: token(toggle-track-disabled-background-color); | ||
border-color: token(toggle-track-disabled-border-color); | ||
cursor: not-allowed; | ||
|
||
path { | ||
fill: #8d95a3 | ||
} | ||
} | ||
|
||
#{$component-root}--readonly #{$component-root}__input + & { | ||
background-color: token(toggle-track-readonly-background-color); | ||
border-color: token(toggle-track-readonly-border-color); | ||
} | ||
|
||
#{$component-root}__input:checked + & { | ||
background-color: token(toggle-track-toggled-background-color); | ||
border: token(toggle-track-toggled-border); | ||
padding: token(toggle-track-toggled-padding); | ||
} | ||
|
||
#{$component-root}__input:checked:hover:enabled + & { | ||
background-color: token(toggle-track-toggled-hover-background-color); | ||
} | ||
|
||
#{$component-root}__input:checked:active:enabled + & { | ||
background-color: token(toggle-track-toggled-active-background-color); | ||
} | ||
|
||
#{$component-root}__input:checked:disabled + & { | ||
background-color: token(toggle-track-toggled-disabled-background-color); | ||
} | ||
|
||
#{$component-root}--readonly #{$component-root}__input:checked + & { | ||
background-color: token(toggle-track-toggled-readonly-background-color); | ||
} | ||
} | ||
|
||
&__handle { | ||
align-content: center; | ||
background-color: token(toggle-handle-background-color); | ||
border-radius: token(toggle-handle-border-radius); | ||
color: token(toggle-handle-toggled-color); | ||
display: inline-flex; | ||
height: token(toggle-handle-height); | ||
justify-content: center; | ||
transition: token(toggle-handle-transition); | ||
width: token(toggle-handle-width); | ||
|
||
#{$component-root}__input:disabled + * & { | ||
background-color: token(toggle-handle-disabled-background-color); | ||
cursor: not-allowed; | ||
} | ||
|
||
#{$component-root}__input:checked + * & { | ||
background-color: token(toggle-handle-toggled-background-color); | ||
height: token(toggle-handle-toggled-height); | ||
transform: translateX(100%); | ||
width: token(toggle-handle-toggled-width); | ||
} | ||
|
||
#{$component-root}__input:checked:disabled + * & { | ||
background-color: token(toggle-handle-toggled-disabled-background-color); | ||
color: token(toggle-handle-toggled-disabled-color); | ||
cursor: not-allowed; | ||
} | ||
|
||
#{$component-root}--readonly #{$component-root}__input:checked + * & { | ||
background-color: token(toggle-handle-toggled-readonly-background-color); | ||
} | ||
} | ||
|
||
&__label-container { | ||
display: flex; | ||
flex-direction: column; | ||
padding-left: $label-padding; | ||
|
||
@include mixins.adyen-checkout-text-body; | ||
|
||
#{$component-root}--label-first > & { | ||
padding-left: 0; | ||
padding-right: $label-padding; | ||
} | ||
} | ||
|
||
&__label { | ||
vertical-align: baseline; | ||
|
||
@include mixins.adyen-checkout-text-body; | ||
} | ||
|
||
.adyen-checkout-toggle__label-text { | ||
font-size: 14px; | ||
font-weight: 400; | ||
letter-spacing: 0; | ||
line-height: 20px; | ||
&__description { | ||
color: token(toggle-description-color); | ||
padding-top: token(toggle-description-padding); | ||
|
||
@include mixins.adyen-checkout-text-body; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/lib/src/components/internal/Toggle/Toggle.test.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 { h } from 'preact'; | ||
import { render, screen } from '@testing-library/preact'; | ||
import userEvent from '@testing-library/user-event'; | ||
import Toggle from './Toggle'; | ||
|
||
test('should emit correct values', async () => { | ||
const user = userEvent.setup(); | ||
const onChangeMock = jest.fn(); | ||
|
||
render(<Toggle checked={false} onChange={onChangeMock} />); | ||
|
||
await user.click(screen.getByRole('switch')); | ||
expect(onChangeMock.mock.calls[0][0]).toBe(true); | ||
|
||
await user.click(screen.getByRole('switch')); | ||
expect(onChangeMock.mock.calls[1][0]).toBe(false); | ||
}); | ||
|
||
test('should render as readonly', () => { | ||
render(<Toggle checked={false} readonly />); | ||
expect(screen.getByRole('switch').getAttribute('aria-readonly')).toBe('true'); | ||
}); | ||
|
||
test('should render as disabled', () => { | ||
render(<Toggle checked={false} disabled />); | ||
expect(screen.getByRole('switch')).toBeDisabled(); | ||
}); | ||
|
||
test('should render description', () => { | ||
render(<Toggle checked={false} label="Save details" description="Save all details" />); | ||
expect(screen.getByText('Save all details')).toBeTruthy(); | ||
}); |
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
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
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
Oops, something went wrong.