Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

component spinner #21

Merged
merged 7 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/Demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@
list-item Red
list-item Blue

icon(source="CirclePlusMinor")
icon(:source="icon")
spinner
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';
import { List, ListItem, Icon } from './polaris-vue';
import CirclePlusMinor from '@icons/CirclePlusMinor.svg';

@Component({
components: {
List,
ListItem,
Icon,
},
})
export default class Demo extends Vue {}
@Component
export default class Demo extends Vue {
public icon = CirclePlusMinor;
}
</script>

<style lang="scss">
Expand Down
3 changes: 3 additions & 0 deletions src/assets/spinner-large.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/spinner-small.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/classes/Spinner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Spinner":"Polaris-Spinner","loading":"Polaris-Spinner--loading","sizeSmall":"Polaris-Spinner--sizeSmall","sizeLarge":"Polaris-Spinner--sizeLarge"}
59 changes: 59 additions & 0 deletions src/components/Spinner/README.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Meta, Story, Canvas, ArgsTable } from '@storybook/addon-docs';
import { Spinner } from '@/polaris-vue';

<Meta
title="Components / Feedback indicators / Spinner"
component={ Spinner }
argTypes={{
accessibilityLabel: {
table: {
type: { summary: null },
},
},
hasFocusableParent: {
table: {
type: { summary: null },
},
},
size: {
name: 'size',
description: 'Size of Spinner',
options: [
'large',
'small',
],
control: { type: 'select' },
table: {
defaultValue: {
summary: 'large'
},
type: {
summary: null,
},
},
},
default: {
table: {
disable: true,
},
},
}}
/>

export const Template = (args, { argTypes }) => ({
props: Object.keys(argTypes),
components: { Spinner},
template: `<Spinner v-bind="$props"/>`,
});

# Spinner

Spinners are used to notify merchants that their action is being processed. For loading states, spinners should only be used for content that can’t be represented with skeleton loading components, like for data charts.

<Canvas>
<Story name="Spinner">
{Template.bind({})}
</Story>
</Canvas>

<ArgsTable story="Spinner" />
66 changes: 66 additions & 0 deletions src/components/Spinner/Spinner.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<template lang="pug">
div
span(:class="className")
SpinnerIconLarge(v-if="size === 'large'")
SpinnerIconSmall(v-else)
span(v-bind="spanAttributes")
VisuallyHidden
span {{ accessibilityLabel }}
</template>

<script lang="ts">
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';
import { classNames, variationName } from 'polaris-react/src/utilities/css';
import { VisuallyHidden } from '../VisuallyHidden';
import styles from '@/classes/Spinner.json';
import SpinnerIconLarge from '@/assets/spinner-large.svg';
import SpinnerIconSmall from '@/assets/spinner-small.svg';

type Size = 'small' | 'large';

@Component({
components: {
VisuallyHidden,
SpinnerIconLarge,
SpinnerIconSmall,
},
})
export default class Spinner extends Vue {
/**
* Size of Spinner
* @values small | large
*/
@Prop({ type: String, default: 'large' })
public size!: Size;

/**
* Accessible label for the spinner
*/
@Prop({ type: String })
public accessibilityLabel!: string;

/**
* Allows the component to apply the correct accessibility roles based on focus
*/
@Prop({ type: Boolean })
public hasFocusableParent!: boolean;

get className() {
const variation = variationName('size', this.size) as keyof typeof styles;

return classNames(
styles.Spinner,
this.size && styles[variation],
);
}

public spanAttributes = {
...(!this.hasFocusableParent && { role: 'status' }),
};
}
</script>

<style lang="scss">
@import 'polaris-react/src/components/Spinner/Spinner.scss';
</style>
1 change: 1 addition & 0 deletions src/components/Spinner/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Spinner } from './Spinner.vue';
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './Icon';
export * from './VisuallyHidden';
export * from './InlineError';
export * from './Choice';
export * from './Spinner';