-
Notifications
You must be signed in to change notification settings - Fork 13.4k
feat(spinner): add recipe and tokens #31014
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
Changes from 6 commits
0a3f41d
5eee3a8
75a325a
53d06e1
78cfbba
edb0414
2ffac3e
3d89f21
363cddf
7b13706
b2a301a
5f0020c
1179d40
4f5ee31
2cd0043
4c1c6d2
ee53528
8019941
0aef08c
cb80321
5388749
de06eb8
7e1f630
3c5afb3
8668db4
528cb40
e00d1f0
062a7c7
95b1b41
a8892a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ion-spinner {
--ion-color-medium-bold: #626262;
} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,29 @@ | ||
| @import "../../themes/mixins"; | ||
| // Required to use the current-color function | ||
| @import "../../themes/functions.color"; | ||
| @use "../../themes/mixins" as mixins; | ||
| @use "../../themes/functions.color" as colors; | ||
|
|
||
| // Spinners | ||
| // Spinner: Common Styles | ||
| // -------------------------------------------------- | ||
|
|
||
| :host { | ||
| /** | ||
| * @prop --color: Color of the spinner | ||
| */ | ||
| --color: var(--ion-spinner-color); | ||
|
|
||
| display: inline-block; | ||
| position: relative; | ||
|
|
||
| width: 28px; | ||
| height: 28px; | ||
|
|
||
| color: var(--color); | ||
|
|
||
| user-select: none; | ||
| } | ||
|
|
||
| :host(.ion-color) { | ||
| color: current-color(base); | ||
| color: colors.current-color(base); | ||
| } | ||
|
|
||
| svg { | ||
| @include transform-origin(center); | ||
| @include mixins.transform-origin(center); | ||
|
|
||
| position: absolute; | ||
|
|
||
|
|
@@ -45,9 +42,10 @@ svg { | |
| transform: translateZ(0); | ||
| } | ||
|
|
||
| // Spinner: lines / lines-small / lines-sharp / lines-sharp-small | ||
| // Spinner Names | ||
|
brandyscarney marked this conversation as resolved.
|
||
| // -------------------------------------------------- | ||
|
|
||
| // lines / lines-small / lines-sharp / lines-sharp-small | ||
| :host(.spinner-lines) line, | ||
| :host(.spinner-lines-small) line, | ||
| :host(.spinner-lines-sharp) line, | ||
|
|
@@ -63,52 +61,58 @@ svg { | |
| animation: spinner-fade-out 1s linear infinite; | ||
| } | ||
|
|
||
| // Spinner: bubbles | ||
| // -------------------------------------------------- | ||
| :host(.spinner-lines) line { | ||
| stroke-width: var(--ion-spinner-lines-stroke-width); | ||
| } | ||
|
|
||
| :host(.spinner-lines-small) line { | ||
| stroke-width: var(--ion-spinner-lines-small-stroke-width); | ||
| } | ||
|
|
||
| :host(.spinner-lines-sharp) line { | ||
| stroke-width: var(--ion-spinner-lines-sharp-stroke-width); | ||
| } | ||
|
|
||
| :host(.spinner-lines-sharp-small) line { | ||
| stroke-width: var(--ion-spinner-lines-sharp-small-stroke-width); | ||
| } | ||
|
|
||
| // bubbles | ||
| :host(.spinner-bubbles) svg { | ||
| animation: spinner-scale-out 1s linear infinite; | ||
| fill: currentColor; | ||
| } | ||
|
|
||
| // Spinner: circles | ||
| // -------------------------------------------------- | ||
|
|
||
| // circles | ||
| :host(.spinner-circles) svg { | ||
| animation: spinner-fade-out 1s linear infinite; | ||
| fill: currentColor; | ||
| } | ||
|
|
||
| // Spinner: crescent | ||
| // -------------------------------------------------- | ||
|
|
||
| :host(.spinner-crescent) circle { | ||
| fill: transparent; | ||
| stroke-width: 4px; | ||
| stroke-width: var(--ion-spinner-crescent-stroke-width); | ||
| stroke-dasharray: 128px; | ||
| stroke-dashoffset: 82px; | ||
| stroke: currentColor; | ||
| } | ||
|
|
||
| // crescent | ||
| :host(.spinner-crescent) svg { | ||
| animation: spinner-rotate 1s linear infinite; | ||
| } | ||
|
|
||
| // Spinner: dots | ||
| // -------------------------------------------------- | ||
|
|
||
| // dots | ||
| :host(.spinner-dots) circle { | ||
| stroke-width: 0; | ||
| stroke-width: var(--ion-spinner-dots-stroke-width); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm having a hard time finding where this is defined. Is it actually set anywhere yet?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| fill: currentColor; | ||
| } | ||
|
|
||
| :host(.spinner-dots) svg { | ||
| animation: spinner-dots 1s linear infinite; | ||
| } | ||
|
|
||
| // Spinner: circular | ||
| // -------------------------------------------------- | ||
|
|
||
| // circular | ||
| :host(.spinner-circular) svg { | ||
| animation: spinner-circular linear infinite; | ||
| } | ||
|
|
@@ -118,13 +122,42 @@ svg { | |
| stroke: currentColor; | ||
| stroke-dasharray: 80px, 200px; | ||
| stroke-dashoffset: 0px; | ||
| stroke-width: 5.6; | ||
| stroke-width: var(--ion-spinner-circular-stroke-width); | ||
| fill: none; | ||
| } | ||
|
|
||
| // Spinner: paused | ||
| // Spinner Sizes | ||
| // -------------------------------------------------- | ||
|
|
||
| :host(.spinner-xsmall) { | ||
| width: var(--ion-spinner-size-xsmall-width); | ||
| height: var(--ion-spinner-size-xsmall-height); | ||
| } | ||
|
|
||
| :host(.spinner-small) { | ||
| width: var(--ion-spinner-size-small-width); | ||
| height: var(--ion-spinner-size-small-height); | ||
| } | ||
|
|
||
| :host(.spinner-medium) { | ||
| width: var(--ion-spinner-size-medium-width); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old code had
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I've been purposely been avoiding setting hard coded values as defaults. Developers wouldn't experience this if they use any of the in built themes. If they decide to make their own, then I would expect that they would know to set their own values either by using their own or copying it from one of the in built themes. If we find out that we should be setting defaults, then we can always come back to add them. |
||
| height: var(--ion-spinner-size-medium-height); | ||
| } | ||
|
|
||
| :host(.spinner-large) { | ||
| width: var(--ion-spinner-size-large-width); | ||
| height: var(--ion-spinner-size-large-height); | ||
| } | ||
|
|
||
| :host(.spinner-xlarge) { | ||
| width: var(--ion-spinner-size-xlarge-width); | ||
| height: var(--ion-spinner-size-xlarge-height); | ||
| } | ||
|
|
||
| // Spinner States | ||
| // -------------------------------------------------- | ||
|
|
||
| // Paused | ||
| :host(.spinner-paused), | ||
| :host(.spinner-paused) svg, | ||
| :host(.spinner-paused) circle { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ import { Component, Host, Prop, h } from '@stencil/core'; | |
| import { createColorClasses } from '@utils/theme'; | ||
|
|
||
| import { config } from '../../global/config'; | ||
| import { getIonTheme, getIonMode } from '../../global/ionic-global'; | ||
| import { getIonMode } from '../../global/ionic-global'; | ||
| import type { Color } from '../../interface'; | ||
|
|
||
| import type { SpinnerTypes } from './spinner-configs'; | ||
|
|
@@ -12,15 +12,10 @@ import type { SpinnerConfig } from './spinner-interface'; | |
|
|
||
| /** | ||
| * @virtualProp {"ios" | "md"} mode - The mode determines the platform behaviors of the component. | ||
| * @virtualProp {"ios" | "md" | "ionic"} theme - The theme determines the visual appearance of the component. | ||
| */ | ||
| @Component({ | ||
| tag: 'ion-spinner', | ||
| styleUrls: { | ||
| ios: 'spinner.native.scss', | ||
| md: 'spinner.native.scss', | ||
| ionic: 'spinner.ionic.scss', | ||
| }, | ||
| styleUrl: 'spinner.scss', | ||
| shadow: true, | ||
| }) | ||
| export class Spinner implements ComponentInterface { | ||
|
|
@@ -54,7 +49,7 @@ export class Spinner implements ComponentInterface { | |
| * Set to `"large"` for a large size. | ||
| * Set to `"xlarge"` for the largest size. | ||
| * | ||
| * Defaults to `"xsmall"` for the `ionic` theme, undefined for all other themes. | ||
| * Defaults to `"medium"`. | ||
|
brandyscarney marked this conversation as resolved.
Outdated
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This says "Defaults to medium" but the ionic theme overrides it to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this sound? 8668db4 |
||
| */ | ||
| @Prop() size?: 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge'; | ||
|
|
||
|
|
@@ -67,29 +62,22 @@ export class Spinner implements ComponentInterface { | |
| return mode === 'ios' ? 'lines' : 'circular'; | ||
| } | ||
|
|
||
| private getSize(): string | undefined { | ||
| const theme = getIonTheme(this); | ||
| const { size } = this; | ||
|
|
||
| // TODO(ROU-10912): Remove theme check when sizes are defined for all themes. | ||
| if (theme !== 'ionic') { | ||
| return undefined; | ||
| } | ||
|
|
||
| if (size === undefined) { | ||
| return 'xsmall'; | ||
| } | ||
| /** | ||
| * Set the size based on the custom theme config | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be get the size, and also it's not just based on the config but also whether or not its set on the component.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated it for chip too: 4f5ee31
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we reword this something like: /**
* Gets the spinner size. Uses the `size` property if set, otherwise
* checks the theme config and falls back to 'medium' if neither is provided.
*/Could replace
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| */ | ||
| get sizeValue(): string { | ||
| const sizeConfig = config.getObjectValue('IonSpinner.size', 'medium') as string; | ||
| console.log('sizeConfig', sizeConfig); | ||
| const size = this.size || sizeConfig; | ||
|
|
||
| return size; | ||
| } | ||
|
|
||
| render() { | ||
| const self = this; | ||
| const theme = getIonTheme(self); | ||
| const spinnerName = self.getName(); | ||
| const size = this.getSize(); | ||
| const { duration: animatedDuration, color, paused, sizeValue } = this; | ||
| const spinnerName = this.getName(); | ||
| const spinner = SPINNERS[spinnerName] ?? SPINNERS['lines']; | ||
| const duration = typeof self.duration === 'number' && self.duration > 10 ? self.duration : spinner.dur; | ||
| const duration = typeof animatedDuration === 'number' && animatedDuration > 10 ? animatedDuration : spinner.dur; | ||
| const svgs: SVGElement[] = []; | ||
|
|
||
| if (spinner.circles !== undefined) { | ||
|
|
@@ -104,11 +92,10 @@ export class Spinner implements ComponentInterface { | |
|
|
||
| return ( | ||
| <Host | ||
| class={createColorClasses(self.color, { | ||
| [theme]: true, | ||
| class={createColorClasses(color, { | ||
| [`spinner-${spinnerName}`]: true, | ||
| 'spinner-paused': self.paused || config.getBoolean('_testing'), | ||
| [`spinner-${size}`]: size !== undefined, | ||
| 'spinner-paused': paused || config.getBoolean('_testing'), | ||
| [`spinner-${sizeValue}`]: true, | ||
| })} | ||
| role="progressbar" | ||
| style={spinner.elmDuration ? { animationDuration: duration + 'ms' } : {}} | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only removed the word |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description says:
But we still have this variable, why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we discussed that it would be revisited as we add more components. Should I just remove them?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I thought that was just about the focus variables. I don't see a reason they can't override the
--coloron components directly? Developers might want it to be different than the global theme.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then they can override them per component by using
--ion-spinner-colorinstead of--color. I ended up removing the old CSS variables since having both might be confusing of when to use them, the same for chip: 0aef08c and 7e1f630