-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(inline-spinner): add experimental component (#503)
* feat(icons): add experimental spinner icon * feat(inline-spinner): add experimental component * feat(button): use experimental inline-spinner * feat(icon-button): use experimental inline-spinner --------- Co-authored-by: Lena Rashkovan <[email protected]>
- Loading branch information
Showing
8 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/components/experimental/InlineSpinner/InlineSpinner.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from 'react'; | ||
import styled, { keyframes } from 'styled-components'; | ||
import { compose, variant } from 'styled-system'; | ||
import SpinnerIcon from '../../../icons/experimental/SpinnerIcon'; | ||
import { getSemanticValue } from '../../../essentials/experimental'; | ||
|
||
interface InlineSpinnerProps { | ||
/** | ||
* Override the color of the spinner | ||
*/ | ||
color?: string; | ||
/** | ||
* Set the size of the component | ||
*/ | ||
size?: 'small' | 'medium' | 'large'; | ||
} | ||
|
||
const sizeVariant = variant({ | ||
prop: 'size', | ||
variants: { | ||
small: { | ||
width: '1rem', | ||
height: '1rem' | ||
}, | ||
medium: { | ||
width: '1.25rem', | ||
height: '1.25rem' | ||
}, | ||
large: { | ||
width: '2.5rem', | ||
height: '2.5rem' | ||
} | ||
} | ||
}); | ||
|
||
const rotation = keyframes` | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
`; | ||
|
||
const Wrapper = styled.span<InlineSpinnerProps>` | ||
display: inline-flex; | ||
box-sizing: border-box; | ||
vertical-align: text-bottom; | ||
${compose(sizeVariant)} | ||
`; | ||
|
||
const Icon = styled(SpinnerIcon)` | ||
width: 100%; | ||
height: 100%; | ||
animation: ${rotation} 750ms linear infinite; | ||
`; | ||
|
||
const InlineSpinner: React.FC<InlineSpinnerProps> = ({ | ||
color = getSemanticValue('interactive'), | ||
size = 'medium', | ||
...rest | ||
}: InlineSpinnerProps) => ( | ||
<Wrapper aria-busy="true" size={size}> | ||
<Icon color={color} {...rest} /> | ||
</Wrapper> | ||
); | ||
|
||
export { InlineSpinner, InlineSpinnerProps }; |
22 changes: 22 additions & 0 deletions
22
src/components/experimental/InlineSpinner/docs/InlineSpinner.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { InlineSpinner } from '../InlineSpinner'; | ||
|
||
const meta: Meta = { | ||
title: 'Experimental/Components/InlineSpinner', | ||
component: InlineSpinner, | ||
parameters: { | ||
layout: 'centered' | ||
}, | ||
argTypes: { | ||
size: { | ||
control: 'radio', | ||
options: ['large', 'medium', 'small'] | ||
} | ||
} | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof InlineSpinner>; | ||
|
||
export const Default: Story = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// DO NOT EDIT. This file was generated by running `npm run generate`.; | ||
import * as React from 'react'; | ||
import { get } from '../../utils/themeGet'; | ||
import { IconProps } from '../IconProps'; | ||
type Props = IconProps; | ||
const SpinnerIcon: React.FC<Props> = ({ size = 'medium', color = 'inherit', ...rest }) => { | ||
const props = { ...rest, color }; | ||
const sizePx = Number.isFinite(size as number) | ||
? size | ||
: get(`iconSizes.${size}`)(props) || get('iconSizes.medium')(props); | ||
return ( | ||
<svg | ||
{...props} | ||
width={sizePx} | ||
height={sizePx} | ||
viewBox="0 0 20 20" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M10 16.482a6.482 6.482 0 010-12.963V1.667A8.333 8.333 0 1018.333 10h-1.852A6.482 6.482 0 0110 16.482z" | ||
fill="currentColor" | ||
/> | ||
</svg> | ||
); | ||
}; | ||
export default SpinnerIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export { default as CalendarTodayOutlineIcon } from './CalendarTodayOutlineIcon'; | ||
export { default as AccountOutlineIcon } from "./AccountOutlineIcon"; | ||
export { default as CarGroupOutlineIcon } from "./CarGroupOutlineIcon"; | ||
export { default as CarOutlineIcon } from "./CarOutlineIcon"; | ||
export { default as LocationIcon } from "./LocationIcon"; | ||
export { default as AccountOutlineIcon } from './AccountOutlineIcon'; | ||
export { default as CarGroupOutlineIcon } from './CarGroupOutlineIcon'; | ||
export { default as CarOutlineIcon } from './CarOutlineIcon'; | ||
export { default as LocationIcon } from './LocationIcon'; | ||
export { default as SpinnerIcon } from './SpinnerIcon'; |