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

feat(components/atom/label): open classnames #2806

Merged
merged 1 commit into from
Jan 17, 2025
Merged
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
41 changes: 32 additions & 9 deletions components/atom/label/src/index.tsx
Original file line number Diff line number Diff line change
@@ -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>
4 changes: 2 additions & 2 deletions components/atom/label/test/index.test.tsx
Original file line number Diff line number Diff line change
@@ -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*`))
@@ -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
})
})