-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Label component and improved radio/checkbox labels
Also added a bunch of required-stars that were missing in forms
- Loading branch information
Showing
18 changed files
with
260 additions
and
185 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@import url('~app/styles/variables.css'); | ||
|
||
.label { | ||
font-size: var(--font-size-lg); | ||
margin-bottom: var(--spacing-xs); | ||
} | ||
|
||
.inline { | ||
cursor: pointer; | ||
|
||
.label { | ||
font-size: inherit; | ||
margin-bottom: 0; | ||
} | ||
} | ||
|
||
.required { | ||
color: var(--danger-color); | ||
font-weight: 600; | ||
margin-left: 2px; | ||
} | ||
|
||
.description { | ||
display: inline-block; | ||
vertical-align: top; | ||
margin-left: var(--spacing-sm); | ||
} | ||
|
||
.fieldSet { | ||
border: 0; | ||
} | ||
|
||
.fieldSetLegend { | ||
margin-bottom: var(--spacing-sm); | ||
} |
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,96 @@ | ||
import { Flex, Icon } from '@webkom/lego-bricks'; | ||
import cx from 'classnames'; | ||
import { HelpCircle } from 'lucide-react'; | ||
import Tooltip from 'app/components/Tooltip'; | ||
import styles from './Label.module.css'; | ||
import type { HTMLProps, ReactNode } from 'react'; | ||
|
||
type LabelTextProps = { | ||
label: ReactNode; | ||
description?: string; | ||
required?: boolean; | ||
className?: string; | ||
}; | ||
|
||
const LabelText = ({ | ||
label, | ||
description, | ||
required, | ||
className, | ||
}: LabelTextProps) => ( | ||
<div className={cx(styles.label, className)}> | ||
{label} | ||
{required && <span className={styles.required}>*</span>} | ||
{description && ( | ||
<Tooltip content={description} className={styles.description}> | ||
<Icon size={20} iconNode={<HelpCircle />} /> | ||
</Tooltip> | ||
)} | ||
</div> | ||
); | ||
|
||
type LabelProps = HTMLProps<HTMLLabelElement> & { | ||
label: ReactNode; | ||
noLabel?: boolean; | ||
description?: string; | ||
required?: boolean; | ||
inline?: boolean; | ||
}; | ||
|
||
export const Label = ({ | ||
label, | ||
noLabel, | ||
description, | ||
required, | ||
inline, | ||
children, | ||
...labelProps | ||
}: LabelProps) => { | ||
const LabelComponent = noLabel ? 'span' : 'label'; | ||
const labelElement = ( | ||
<LabelText label={label} description={description} required={required} /> | ||
); | ||
return ( | ||
<LabelComponent {...labelProps}> | ||
{inline ? ( | ||
<Flex | ||
alignItems="center" | ||
gap="var(--spacing-xs)" | ||
className={styles.inline} | ||
> | ||
{children} | ||
{labelElement} | ||
</Flex> | ||
) : ( | ||
<> | ||
{labelElement} | ||
{children} | ||
</> | ||
)} | ||
</LabelComponent> | ||
); | ||
}; | ||
|
||
type FieldSetProps = HTMLProps<HTMLFieldSetElement> & { | ||
legend: string; | ||
description?: string; | ||
required?: boolean; | ||
children: ReactNode; | ||
}; | ||
export const FieldSet = ({ | ||
legend, | ||
description, | ||
required, | ||
children, | ||
...fieldSetProps | ||
}: FieldSetProps) => ( | ||
<fieldset | ||
className={cx(styles.fieldSet, fieldSetProps.className)} | ||
{...fieldSetProps} | ||
> | ||
<legend className={styles.fieldSetLegend}> | ||
<LabelText label={legend} description={description} required={required} /> | ||
</legend> | ||
{children} | ||
</fieldset> | ||
); |
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
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.