Skip to content

Commit

Permalink
[OP-144] Icon example for button (#215)
Browse files Browse the repository at this point in the history
This PR updates the badge documentation to allow seeing the prefix and suffix icons separately. It also brings that same demonstration to the button documentation.
  • Loading branch information
Jeremy-Walton authored Feb 7, 2024
1 parent 39b4e2f commit f8b4a56
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/stories/Components/Badge/Badge.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { createIcon } from '../Icon/Icon.js'

export const createBadge = ({ label, style = 'default', pill = false, inButton = 'no', showIcons = false }) => {
export const createBadge = ({
label,
style = 'default',
pill = false,
inButton = 'no',
showPrefixIcon = false,
showSuffixIcon = false,
}) => {
const badge = document.createElement('div')
badge.innerText = label

badge.className = [style === 'default' ? 'badge' : `badge-${style}`, pill ? 'badge--pill' : '']
.filter(Boolean)
.join(' ')

if (showIcons) {
if (showPrefixIcon) {
badge.prepend(createIcon({ name: 'open_in_new' }))
}

if (showSuffixIcon) {
badge.appendChild(createIcon({ name: 'add' }))
}

Expand Down
6 changes: 5 additions & 1 deletion src/stories/Components/Badge/Badge.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export default {
control: { type: 'select' },
options: ['no', 'right', 'left'],
},
showIcons: {
showPrefixIcon: {
control: 'boolean',
description: 'This is not a class. It just provides an example of using icons within a badge',
},
showSuffixIcon: {
control: 'boolean',
description: 'This is not a class. It just provides an example of using icons within a badge',
},
Expand Down
10 changes: 10 additions & 0 deletions src/stories/Components/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const createButton = ({
disabled = false,
inlineIconWithLabel = false,
useAsLink = false,
showPrefixIcon = false,
showSuffixIcon = false,
}) => {
const element = useAsLink || disabled ? 'a' : 'button'
const btn = document.createElement(element)
Expand All @@ -33,6 +35,14 @@ export const createButton = ({
btn.prepend(createIcon({ name: 'add', size: 'large' }))
}

if (showPrefixIcon) {
btn.prepend(createIcon({ name: 'open_in_new' }))
}

if (showSuffixIcon) {
btn.appendChild(createIcon({ name: 'add' }))
}

btn.className = [
priority === 'default' ? 'btn' : `btn-${priority}`,
noBorder ? 'btn--no-border' : '',
Expand Down
8 changes: 8 additions & 0 deletions src/stories/Components/Button/Button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export default {
pill: { control: 'boolean' },
icon: { control: 'boolean' },
iconWithLabel: { control: 'boolean' },
showPrefixIcon: {
control: 'boolean',
description: 'This is not a class. It just provides an example of using icons within a button',
},
showSuffixIcon: {
control: 'boolean',
description: 'This is not a class. It just provides an example of using icons within a button',
},
size: {
control: { type: 'select' },
options: ['small', 'medium', 'large'],
Expand Down

0 comments on commit f8b4a56

Please sign in to comment.