Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve SideLabel positioning #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
)
Loading