From 4ad47129740193774be4b7f6bb2f8698c5b42b84 Mon Sep 17 00:00:00 2001 From: Natallia Harshunova Date: Mon, 17 Jun 2024 14:37:00 +0200 Subject: [PATCH 1/5] feat(18794): add left label feature to toggler --- packages/ui-kit/src/Toggler/Toggler.fixture.tsx | 2 ++ packages/ui-kit/src/Toggler/index.tsx | 13 +++++++++---- packages/ui-kit/src/Toggler/style.module.css | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/packages/ui-kit/src/Toggler/Toggler.fixture.tsx b/packages/ui-kit/src/Toggler/Toggler.fixture.tsx index 2d756b70..75b96bd8 100644 --- a/packages/ui-kit/src/Toggler/Toggler.fixture.tsx +++ b/packages/ui-kit/src/Toggler/Toggler.fixture.tsx @@ -16,6 +16,7 @@ export default { foo: false, bar: true, baz: false, + payment: false, }); const onChange = useCallback((e: React.ChangeEvent) => { @@ -27,6 +28,7 @@ export default { + {JSON.stringify(state, null, 2)} ); diff --git a/packages/ui-kit/src/Toggler/index.tsx b/packages/ui-kit/src/Toggler/index.tsx index 6a93d219..6b2d8ea4 100644 --- a/packages/ui-kit/src/Toggler/index.tsx +++ b/packages/ui-kit/src/Toggler/index.tsx @@ -5,7 +5,8 @@ import type { ChangeEvent } from 'react'; interface Toggler { id: string; name?: string; - label?: React.ReactChild | React.ReactChild[]; + label?: React.ReactNode; + leftLabel?: React.ReactNode; className?: string; onChange?: (e: ChangeEvent) => void; on?: boolean; @@ -14,6 +15,7 @@ interface Toggler { export function Toggler({ name, label, + leftLabel, className = '', id, on = false, @@ -21,10 +23,13 @@ export function Toggler({ }: Toggler & React.DetailedHTMLProps, HTMLInputElement>): React.ReactElement { return ( - ); From 4ffb015fab73e0b0bf7e2a9d997070be732e556b Mon Sep 17 00:00:00 2001 From: Natallia Harshunova Date: Mon, 17 Jun 2024 17:25:04 +0200 Subject: [PATCH 4/5] feat(18794): add ability to specify labels classes --- .../Toggler/Toggler.fixture.style.module.css | 10 ++++++++++ packages/ui-kit/src/Toggler/Toggler.fixture.tsx | 15 ++++++++++++++- packages/ui-kit/src/Toggler/index.tsx | 17 ++++++++++++++--- packages/ui-kit/src/Toggler/style.module.css | 14 ++------------ 4 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 packages/ui-kit/src/Toggler/Toggler.fixture.style.module.css diff --git a/packages/ui-kit/src/Toggler/Toggler.fixture.style.module.css b/packages/ui-kit/src/Toggler/Toggler.fixture.style.module.css new file mode 100644 index 00000000..e2651546 --- /dev/null +++ b/packages/ui-kit/src/Toggler/Toggler.fixture.style.module.css @@ -0,0 +1,10 @@ +.label { + font-weight: 600; + font-size: 16px; + line-height: 20px; + color: var(--faint-strong-up); + + &.active { + color: var(--base-strong); + } +} diff --git a/packages/ui-kit/src/Toggler/Toggler.fixture.tsx b/packages/ui-kit/src/Toggler/Toggler.fixture.tsx index 75b96bd8..2ebea81b 100644 --- a/packages/ui-kit/src/Toggler/Toggler.fixture.tsx +++ b/packages/ui-kit/src/Toggler/Toggler.fixture.tsx @@ -1,4 +1,5 @@ import { useCallback, useState } from 'react'; +import s from './Toggler.fixture.style.module.css'; import { Toggler } from '.'; export default { @@ -19,6 +20,11 @@ export default { payment: false, }); + const classes = { + label: s.label, + activeLabel: s.active, + }; + const onChange = useCallback((e: React.ChangeEvent) => { setState((state) => ((state[e.target.id] = e.target.checked), { ...state })); }, []); @@ -28,7 +34,14 @@ export default { - + {JSON.stringify(state, null, 2)} ); diff --git a/packages/ui-kit/src/Toggler/index.tsx b/packages/ui-kit/src/Toggler/index.tsx index 084d43d5..e0b766bb 100644 --- a/packages/ui-kit/src/Toggler/index.tsx +++ b/packages/ui-kit/src/Toggler/index.tsx @@ -7,6 +7,10 @@ interface Toggler { name?: string; label?: React.ReactNode; leftLabel?: React.ReactNode; + classes?: { + label?: string; + activeLabel?: string; + }; className?: string; onChange?: (e: ChangeEvent) => void; on?: boolean; @@ -17,6 +21,7 @@ export function Toggler({ label, leftLabel, className = '', + classes, id, on = false, ...native @@ -24,12 +29,18 @@ export function Toggler({ React.DetailedHTMLProps, HTMLInputElement>): React.ReactElement { return ( ); } diff --git a/packages/ui-kit/src/Toggler/style.module.css b/packages/ui-kit/src/Toggler/style.module.css index e2c89df9..4456afda 100644 --- a/packages/ui-kit/src/Toggler/style.module.css +++ b/packages/ui-kit/src/Toggler/style.module.css @@ -57,20 +57,10 @@ } } -.twoLabels { +.twoDirectional { .toggle { background-color: var(--base-strong); - margin: 0 0.5em 0 0.5em; - } - .label { - font-weight: 600; - font-size: 16px; - line-height: 20px; - color: var(--faint-strong-up); - - &.active { - color: var(--base-strong); - } + margin-left: 0.5em; } } From 559c05fb9327d07f4708839568d93fe88664613f Mon Sep 17 00:00:00 2001 From: Natallia Harshunova Date: Mon, 17 Jun 2024 19:37:41 +0200 Subject: [PATCH 5/5] feat(18794): rename leftLabel -> offValueLabel --- .../ui-kit/src/Toggler/Toggler.fixture.tsx | 24 ++++++++++--------- packages/ui-kit/src/Toggler/index.tsx | 10 ++++---- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/ui-kit/src/Toggler/Toggler.fixture.tsx b/packages/ui-kit/src/Toggler/Toggler.fixture.tsx index 2ebea81b..a931703c 100644 --- a/packages/ui-kit/src/Toggler/Toggler.fixture.tsx +++ b/packages/ui-kit/src/Toggler/Toggler.fixture.tsx @@ -17,16 +17,15 @@ export default { foo: false, bar: true, baz: false, - payment: false, + isAnnualPayment: false, }); - const classes = { - label: s.label, - activeLabel: s.active, - }; - const onChange = useCallback((e: React.ChangeEvent) => { - setState((state) => ((state[e.target.id] = e.target.checked), { ...state })); + const { id, checked } = e.target; + setState((prevState) => ({ + ...prevState, + [id]: checked, + })); }, []); return ( @@ -35,12 +34,15 @@ export default { {JSON.stringify(state, null, 2)} diff --git a/packages/ui-kit/src/Toggler/index.tsx b/packages/ui-kit/src/Toggler/index.tsx index e0b766bb..9c75bd2a 100644 --- a/packages/ui-kit/src/Toggler/index.tsx +++ b/packages/ui-kit/src/Toggler/index.tsx @@ -6,7 +6,7 @@ interface Toggler { id: string; name?: string; label?: React.ReactNode; - leftLabel?: React.ReactNode; + offValueLabel?: React.ReactNode; classes?: { label?: string; activeLabel?: string; @@ -19,7 +19,7 @@ interface Toggler { export function Toggler({ name, label, - leftLabel, + offValueLabel, className = '', classes, id, @@ -31,13 +31,13 @@ export function Toggler({