Skip to content

Commit

Permalink
Use className when provided
Browse files Browse the repository at this point in the history
  • Loading branch information
runely committed Mar 26, 2022
1 parent b43e6a1 commit d1259b2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/ui/TextField/TextField.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { boolean, number, text } from '@storybook/addon-knobs'

import { TextField } from '.'

import './stories.styles.scss'

export default getConfig(
{ title: 'TextField', component: TextField }
)
Expand Down Expand Up @@ -119,3 +121,12 @@ export function Required () {
</div>
)
}

export function WithClassName () {
return (
<div>
<TextField placeholder='red' className='red' value='className = red' />
<TextField placeholder='green' className='green' value='className = green' />
</div>
)
}
3 changes: 2 additions & 1 deletion src/ui/TextField/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export function TextField ({ type, className, placeholder, required, value, id,
// Determine what classes the component should have
const componentClasses = useMemo(() => {
let classes = 'textfield'
if (className) classes += ` ${className}`
if (type && typeof type === 'string') classes += ` ${type}`
if (required) classes += ' required-input'
if (rounded) classes += ' rounded'
Expand All @@ -58,7 +59,7 @@ export function TextField ({ type, className, placeholder, required, value, id,
classes = classes.trim()

return classes
}, [hasData, focusState, type, required, rounded, error, alwaysPlaceholder])
}, [hasData, focusState, type, required, rounded, error, alwaysPlaceholder, className])

// Determine what classes the input should have
const inputClasses = useMemo(() => {
Expand Down
11 changes: 11 additions & 0 deletions src/ui/TextField/stories.styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.textfield {
margin-bottom: 15px;
}

.red {
color: red;
}

.green {
color: green;
}

1 comment on commit d1259b2

@vercel
Copy link

@vercel vercel bot commented on d1259b2 Mar 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.