Skip to content

Commit

Permalink
icon button
Browse files Browse the repository at this point in the history
  • Loading branch information
langermank committed Oct 11, 2023
1 parent fae28dd commit 72a0247
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Button/Button.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ export const LoadingTrigger = () => {

const handleClick = () => {
setIsLoading(true)
setTimeout(() => {
setIsLoading(false)
}, 3000)
}

return (
Expand Down
11 changes: 9 additions & 2 deletions src/Button/ButtonBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ const ButtonBase = forwardRef(
data-size={size === 'small' || size === 'large' ? size : undefined}
data-no-visuals={!LeadingVisual && !TrailingVisual && !TrailingAction ? true : undefined}
aria-disabled={loading ? true : undefined}
aria-describedby={loading ? 'loading-message' : undefined}
>
{Icon ? (
<Icon />
loading ? (
<Spinner size="small" />
) : (
<Icon />
)
) : (
<>
<Box as="span" data-component="buttonContent" sx={getAlignContentSize(alignContent)}>
Expand Down Expand Up @@ -108,7 +113,9 @@ const ButtonBase = forwardRef(
</StyledButton>
{loading && (
<VisuallyHidden>
<span aria-live="polite">Loading</span>
<span aria-live="polite" aria-busy="true" id="loading-message">
Loading
</span>
</VisuallyHidden>
)}
</>
Expand Down
19 changes: 17 additions & 2 deletions src/Button/IconButton.features.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {HeartIcon} from '@primer/octicons-react'
import React from 'react'
import {HeartIcon, DownloadIcon} from '@primer/octicons-react'
import React, {useState} from 'react'
import {IconButton} from '.'

export default {
Expand All @@ -19,3 +19,18 @@ export const Small = () => <IconButton size="small" icon={HeartIcon} aria-label=
export const Medium = () => <IconButton size="medium" icon={HeartIcon} aria-label="Default" />

export const Large = () => <IconButton size="large" icon={HeartIcon} aria-label="Default" />

export const Loading = () => <IconButton loading icon={HeartIcon} variant="primary" aria-label="Primary" />

export const LoadingTrigger = () => {
const [isLoading, setIsLoading] = useState(false)

const handleClick = () => {
setIsLoading(true)
setTimeout(() => {
setIsLoading(false)
}, 3000)
}

return <IconButton loading={isLoading} onClick={handleClick} icon={DownloadIcon} aria-label="Download" />
}

0 comments on commit 72a0247

Please sign in to comment.