Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2710 from teamleadercrm/FRAF-2192
Browse files Browse the repository at this point in the history
Added labelPosition and fullWidth props to Toggle
  • Loading branch information
qubis741 committed Jul 12, 2023
2 parents 4ae0ab5 + efb42a3 commit 74d88f8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

### Changed

- `Popover`: Aligned the popover shadows with our design spec. ([@lowiebenoot](https://https://github.com/lowiebenoot) in [#2708](https://github.com/teamleadercrm/ui/pull/2708))

### Deprecated

### Removed
Expand All @@ -14,6 +12,16 @@

### Dependency updates

## [22.2.0] - 2023-07-11

### Added

- `Toggle`: Props `labelPosition` and `fullWidth`. ([@qubis741](https://github.com/qubis741) in [#2710](https://github.com/teamleadercrm/ui/pull/2710))

### Changed

- `Popover`: Aligned the popover shadows with our design spec. ([@lowiebenoot](https://https://github.com/lowiebenoot) in [#2708](https://github.com/teamleadercrm/ui/pull/2708))

## [22.1.1] - 2023-06-14

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@teamleader/ui",
"description": "Teamleader UI library",
"version": "22.1.1",
"version": "22.2.0",
"author": "Teamleader <development@teamleader.eu>",
"bugs": {
"url": "https://github.com/teamleadercrm/ui/issues"
Expand Down
6 changes: 6 additions & 0 deletions src/components/toggle/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export interface ToggleProps
label?: ReactNode;
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
size?: Exclude<typeof SIZES[number], 'tiny' | 'fullscreen' | 'smallest' | 'hero'>;
labelPosition?: 'left' | 'right';
fullWidth?: boolean;
}

const Toggle: GenericComponent<ToggleProps> = ({
Expand All @@ -38,6 +40,8 @@ const Toggle: GenericComponent<ToggleProps> = ({
size = 'medium',
tooltip,
tooltipPosition,
labelPosition = 'right',
fullWidth = false,
...others
}) => {
const ref = useRef<HTMLInputElement>(null);
Expand All @@ -55,6 +59,8 @@ const Toggle: GenericComponent<ToggleProps> = ({
{
[theme['is-checked']]: checked,
[theme['is-disabled']]: disabled,
[theme['label-on-left']]: labelPosition === 'left',
[theme['is-full-width']]: fullWidth,
},
className,
);
Expand Down
15 changes: 14 additions & 1 deletion src/components/toggle/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
overflow: hidden;
opacity: 0;
margin: 0;
position: absolute;
}

.label {
margin-left: var(--spacer-small);
margin: 0 0 0 var(--spacer-small);
display: flex;
}

Expand Down Expand Up @@ -112,6 +113,18 @@
}
}

&.label-on-left {
flex-direction: row-reverse;
.label {
margin: 0 var(--spacer-small) 0 0;
}
}

&.is-full-width {
justify-content: space-between;
width: 100%;
}

input:focus-visible + .track {
border-color: var(--color-neutral-darkest);
box-shadow: 0 0 0 1px var(--color-neutral-darkest);
Expand Down

0 comments on commit 74d88f8

Please sign in to comment.