Skip to content

Commit

Permalink
Improve SideLabel positioning (#35)
Browse files Browse the repository at this point in the history
# Improve SideLabel positioning

## ♻️ Current situation & Problem
SideLabel needs to be versatile to handle all kind of input/label sizes,
like bigger `Checkbox` or `Switch`.


## ⚙️ Release Notes 
* Add `center` prop
* Remove margin and wrapper to rely on flex properties


![image](https://github.com/user-attachments/assets/ecb0f111-739c-4c4a-84c8-f727ae0dad4d)



## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
arkadiuszbachorski authored Jan 20, 2025
1 parent 0efe4ad commit 9e40078
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src/components/SideLabel/SideLabel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ export const Reversed = () => (
</SideLabel>
)

const complexLabel = (
<>
<h2 className="mb-2 font-bold">Lorem</h2>
<p className="font-light">
Lorem ipsum dolor sit amet, consectetur adipisicing elit
</p>
</>
)

export const Complex = () => (
<SideLabel label={complexLabel}>
<Switch />
</SideLabel>
)

export const ComplexNonCentered = () => (
<SideLabel label={complexLabel} center={false}>
<Switch />
</SideLabel>
)

export const NoInput = () => (
<SideLabel label="Check me">
<span className="hidden">input goes here</span>
Expand Down
15 changes: 12 additions & 3 deletions src/components/SideLabel/SideLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ import { cn } from '../../utils/className'

type SideLabelProps = Omit<HTMLProps<HTMLLabelElement>, 'label'> & {
label?: ReactNode
/* Show label on right side */
/**
* Show label on right side
* */
reverse?: boolean
/**
* Center content vertically
* @default true
* */
center?: boolean
}

/**
Expand All @@ -23,17 +30,19 @@ export const SideLabel = ({
className,
label,
reverse,
center = true,
...props
}: SideLabelProps) => (
<label
className={cn(
'flex cursor-pointer select-none items-center gap-2.5',
'flex cursor-pointer select-none gap-2.5',
reverse && 'flex-row-reverse',
center && 'items-center',
className,
)}
{...props}
>
<div className="mt-1">{children}</div>
{children}
<div className="text-sm leading-none">{label}</div>
</label>
)

0 comments on commit 9e40078

Please sign in to comment.