Skip to content

Commit

Permalink
Merge pull request #2806 from SUI-Components/a11y-label-classNames
Browse files Browse the repository at this point in the history
feat(components/atom/label): open classnames
  • Loading branch information
andresin87 authored Jan 17, 2025
2 parents b6563bc + 9106fbf commit 28ab605
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
41 changes: 32 additions & 9 deletions components/atom/label/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,41 @@ export interface AtomLabelProps extends Pick<LabelHTMLAttributes<HTMLLabelElemen
* Font size: set different font sizes, use AtomLabelFontSizes
*/
fontSize?: FontSize
/**
* class attribute
*/
className?: string
}

const getClass = ({inline, type, fontSize}: Pick<AtomLabelProps, 'inline' | 'type' | 'fontSize'>) =>
cx(CLASSNAME, {
[`${CLASSNAME}--${fontSize as string}`]: Boolean(fontSize),
[`${CLASSNAME}--${type as string}`]: Boolean(type),
[`${CLASSNAME}--inlineLeft`]: inline === 'left',
[`${CLASSNAME}--inlineRight`]: inline === 'right'
})
const getClass = ({
inline,
type,
fontSize,
className
}: Pick<AtomLabelProps, 'inline' | 'type' | 'fontSize' | 'className'>) =>
cx(
CLASSNAME,
{
[`${CLASSNAME}--${fontSize as string}`]: Boolean(fontSize),
[`${CLASSNAME}--${type as string}`]: Boolean(type),
[`${CLASSNAME}--inlineLeft`]: inline === 'left',
[`${CLASSNAME}--inlineRight`]: inline === 'right'
},
className
)

const AtomLabel: FC<AtomLabelProps> = ({name, text, inline, optionalText, type, fontSize, htmlFor, onClick}) => (
<label htmlFor={htmlFor ?? name} className={getClass({inline, type, fontSize})} onClick={onClick}>
const AtomLabel: FC<AtomLabelProps> = ({
name,
text,
inline,
optionalText,
type,
fontSize,
htmlFor,
onClick,
className
}) => (
<label htmlFor={htmlFor ?? name} className={getClass({inline, type, fontSize, className})} onClick={onClick}>
{text}
{Boolean(optionalText) && <span className="sui-AtomLabel-optionalText">{optionalText}</span>}
</label>
Expand Down
4 changes: 2 additions & 2 deletions components/atom/label/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe(json.name, () => {
expect(container.innerHTML).to.not.have.lengthOf(0)
})

it('should NOT extend classNames', () => {
it('should extend classNames', () => {
// Given
const props = {className: 'extended-classNames'}
const findSentence = (str: string) => (string: string) => string.match(new RegExp(`S*${str}S*`))
Expand All @@ -75,7 +75,7 @@ describe(json.name, () => {
const findClassName = findSentence(props.className)

// Then
expect(findClassName(container.innerHTML)).to.be.null
expect(findClassName(container.innerHTML)).to.not.be.null
})
})

Expand Down

0 comments on commit 28ab605

Please sign in to comment.