Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 5b46584

Browse files
committed
feat(Loader): add component
1 parent b329d6a commit 5b46584

File tree

16 files changed

+303
-0
lines changed

16 files changed

+303
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Loader } from '@stardust-ui/react'
2+
import * as React from 'react'
3+
4+
const LoaderExample: React.FC = () => <Loader />
5+
6+
export default LoaderExample
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Loader } from '@stardust-ui/react'
2+
import * as React from 'react'
3+
4+
const LoaderExampleLabel: React.FC = () => <Loader label="Loading..." />
5+
6+
export default LoaderExampleLabel
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as React from 'react'
2+
3+
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample'
4+
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'
5+
6+
const LoaderTypesExamples = () => (
7+
<ExampleSection title="Types">
8+
<ComponentExample
9+
title="Loader"
10+
description="A basic loader."
11+
examplePath="components/Loader/Types/LoaderExample"
12+
/>
13+
<ComponentExample
14+
title="Label"
15+
description="A loader can contain label."
16+
examplePath="components/Loader/Types/LoaderExampleLabel"
17+
/>
18+
</ExampleSection>
19+
)
20+
21+
export default LoaderTypesExamples
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Loader } from '@stardust-ui/react'
2+
import * as React from 'react'
3+
4+
const LoaderExampleInline: React.FC = () => <Loader inline />
5+
6+
export default LoaderExampleInline
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Grid, Loader } from '@stardust-ui/react'
2+
import * as React from 'react'
3+
4+
const LoaderExampleLabel: React.FC = () => (
5+
<Grid columns={2} variables={{ gridGap: '20px' }}>
6+
<Loader label="At start" labelPosition="start" />
7+
<Loader label="At end" labelPosition="end" />
8+
9+
<Loader label="At above" labelPosition="above" />
10+
<Loader label="At below" labelPosition="below" />
11+
</Grid>
12+
)
13+
14+
export default LoaderExampleLabel
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Grid, Loader } from '@stardust-ui/react'
2+
import * as React from 'react'
3+
4+
const LoaderExampleSize: React.FC = () => (
5+
<Grid columns="3" variables={{ gridGap: '20px' }}>
6+
<Loader size="smallest" />
7+
<Loader size="smaller" />
8+
<Loader size="small" />
9+
10+
<Loader size="large" />
11+
<Loader size="larger" />
12+
<Loader size="largest" />
13+
</Grid>
14+
)
15+
16+
export default LoaderExampleSize
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as React from 'react'
2+
3+
import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample'
4+
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'
5+
6+
const LoaderTypesExamples = () => (
7+
<ExampleSection title="Types">
8+
<ComponentExample
9+
title="Inline"
10+
description="Loaders can appear inline with content."
11+
examplePath="components/Loader/Variations/LoaderExampleInline"
12+
/>
13+
<ComponentExample
14+
title="Label Position"
15+
description="A loader can contain label."
16+
examplePath="components/Loader/Variations/LoaderExampleLabelPosition"
17+
/>
18+
<ComponentExample
19+
title="Size"
20+
description="A basic loader."
21+
examplePath="components/Loader/Variations/LoaderExampleSize"
22+
/>
23+
</ExampleSection>
24+
)
25+
26+
export default LoaderTypesExamples
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as React from 'react'
2+
3+
import Types from './Types'
4+
import Variations from './Variations'
5+
6+
const LoaderExamples = () => (
7+
<>
8+
<Types />
9+
<Variations />
10+
</>
11+
)
12+
13+
export default LoaderExamples

src/components/Animation/Animation.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class Animation extends UIComponent<ReactPropsStrict<AnimationProps>, any> {
124124
style: { ...animationStyle, ...(child.props && child.props.style) },
125125
})
126126
: ''
127+
console.log(animationStyle)
127128

128129
return (
129130
<ElementType className={classes.root} {...rest}>

src/components/Loader/Loader.tsx

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import * as PropTypes from 'prop-types'
2+
import * as React from 'react'
3+
4+
import {
5+
UIComponent,
6+
createShorthandFactory,
7+
UIComponentProps,
8+
commonPropTypes,
9+
ColorComponentProps,
10+
} from '../../lib'
11+
import { defaultBehavior } from '../../lib/accessibility'
12+
import { Accessibility } from '../../lib/accessibility/types'
13+
import { ReactProps } from '../../../types/utils'
14+
import Slot from '../Slot/Slot'
15+
16+
export type LoaderPosition = 'above' | 'below' | 'start' | 'end'
17+
export type LoaderSize =
18+
| 'smallest'
19+
| 'smaller'
20+
| 'small'
21+
| 'medium'
22+
| 'large'
23+
| 'larger'
24+
| 'largest'
25+
26+
export interface LoaderProps extends UIComponentProps, ColorComponentProps {
27+
/**
28+
* Accessibility behavior if overridden by the user.
29+
* @default defaultBehavior
30+
*/
31+
accessibility?: Accessibility
32+
labelPosition?: LoaderPosition
33+
size?: LoaderSize
34+
}
35+
36+
/**
37+
* A Loader indicates a possible user action.
38+
*/
39+
class Loader extends UIComponent<ReactProps<LoaderProps>> {
40+
static create: Function
41+
static displayName = 'Loader'
42+
static className = 'ui-loader'
43+
44+
static propTypes = {
45+
...commonPropTypes.createCommon({
46+
children: false,
47+
content: false,
48+
color: true,
49+
}),
50+
accessibility: PropTypes.func,
51+
labelPosition: PropTypes.oneOf(['above', 'below', 'start', 'end']),
52+
size: PropTypes.oneOf(['smallest', 'smaller', 'small', 'medium', 'large', 'larger', 'largest']),
53+
}
54+
55+
static defaultProps = {
56+
accessibility: defaultBehavior,
57+
labelPosition: 'below',
58+
size: 'medium',
59+
}
60+
61+
renderComponent({ ElementType, classes, accessibility, variables, styles, rest }) {
62+
const { label } = this.props
63+
64+
return (
65+
<ElementType className={classes.root} {...accessibility.attributes.root} {...rest}>
66+
{Slot.create('', { defaultProps: { styles: styles.indicator } })}
67+
{Slot.create(label, { defaultProps: { styles: styles.label } })}
68+
</ElementType>
69+
)
70+
}
71+
}
72+
73+
Loader.create = createShorthandFactory(Loader, 'content')
74+
75+
export default Loader

0 commit comments

Comments
 (0)