Skip to content

Commit

Permalink
Import styles more efficiently (#1861)
Browse files Browse the repository at this point in the history
* import styles more efficiently; fixes #1692

* remove scale transition
  • Loading branch information
claviska committed Feb 9, 2024
1 parent 775f301 commit 02ce4db
Show file tree
Hide file tree
Showing 110 changed files with 117 additions and 237 deletions.
7 changes: 0 additions & 7 deletions docs/assets/styles/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,6 @@ html.sidebar-open #menu-toggle {
padding: 0.5rem;
margin: 0;
cursor: pointer;
transition: 250ms scale ease;
}

#theme-selector:not(:defined) {
Expand Down Expand Up @@ -1102,12 +1101,6 @@ html.sidebar-open #menu-toggle {
color: var(--sl-color-neutral-1000);
}

#icon-toolbar button:hover,
#icon-toolbar a:hover,
#theme-selector sl-button:hover {
scale: 1.1;
}

#icon-toolbar a:not(:last-child),
#icon-toolbar button:not(:last-child) {
margin-right: 0.25rem;
Expand Down
1 change: 1 addition & 0 deletions docs/pages/resources/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ New versions of Shoelace are released as-needed and generally occur when a criti
- Added help text to `<sl-switch>` [#1800]
- Fixed a bug in `<sl-option>` that caused HTML tags to be included in `getTextLabel()`
- Fixed a bug in `<sl-carousel>` that caused slides to not switch correctly [#1862]
- Refactored component styles to be consumed more efficiently [#1692]

## 2.13.1

Expand Down
2 changes: 1 addition & 1 deletion scripts/plop/templates/component/component.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { CSSResultGroup } from 'lit';
* @cssproperty --example - An example CSS custom property.
*/
export default class {{ properCase tag }} extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];

private readonly localize = new LocalizeController(this);

Expand Down
3 changes: 2 additions & 1 deletion src/components/alert/alert.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LocalizeController } from '../../utilities/localize.js';
import { property, query } from 'lit/decorators.js';
import { waitForEvent } from '../../internal/event.js';
import { watch } from '../../internal/watch.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import SlIconButton from '../icon-button/icon-button.component.js';
import styles from './alert.styles.js';
Expand Down Expand Up @@ -40,7 +41,7 @@ const toastStack = Object.assign(document.createElement('div'), { className: 'sl
* @animation alert.hide - The animation to use when hiding the alert.
*/
export default class SlAlert extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];
static dependencies = { 'sl-icon-button': SlIconButton };

private autoHideTimeout: number;
Expand Down
3 changes: 0 additions & 3 deletions src/components/alert/alert.styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

export default css`
${componentStyles}
:host {
display: contents;
Expand Down
3 changes: 2 additions & 1 deletion src/components/animated-image/animated-image.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { html } from 'lit';
import { property, query, state } from 'lit/decorators.js';
import { watch } from '../../internal/watch.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import SlIcon from '../icon/icon.component.js';
import styles from './animated-image.styles.js';
Expand All @@ -26,7 +27,7 @@ import type { CSSResultGroup } from 'lit';
* @cssproperty --icon-size - The size of the play/pause icons.
*/
export default class SlAnimatedImage extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];
static dependencies = { 'sl-icon': SlIcon };

@query('.animated-image__animated') animatedImage: HTMLImageElement;
Expand Down
3 changes: 0 additions & 3 deletions src/components/animated-image/animated-image.styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

export default css`
${componentStyles}
:host {
--control-box-size: 3rem;
--icon-size: calc(var(--control-box-size) * 0.625);
Expand Down
3 changes: 2 additions & 1 deletion src/components/animation/animation.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { animations } from './animations.js';
import { html } from 'lit';
import { property, queryAsync } from 'lit/decorators.js';
import { watch } from '../../internal/watch.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import styles from './animation.styles.js';
import type { CSSResultGroup } from 'lit';
Expand All @@ -20,7 +21,7 @@ import type { CSSResultGroup } from 'lit';
* animate multiple elements, either wrap them in a single container or use multiple `<sl-animation>` elements.
*/
export default class SlAnimation extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];

private animation?: Animation;
private hasStarted = false;
Expand Down
3 changes: 0 additions & 3 deletions src/components/animation/animation.styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

export default css`
${componentStyles}
:host {
display: contents;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/avatar/avatar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { classMap } from 'lit/directives/class-map.js';
import { html } from 'lit';
import { property, state } from 'lit/decorators.js';
import { watch } from '../../internal/watch.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import SlIcon from '../icon/icon.component.js';
import styles from './avatar.styles.js';
Expand All @@ -25,7 +26,7 @@ import type { CSSResultGroup } from 'lit';
* @cssproperty --size - The size of the avatar.
*/
export default class SlAvatar extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];
static dependencies = {
'sl-icon': SlIcon
};
Expand Down
3 changes: 0 additions & 3 deletions src/components/avatar/avatar.styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

export default css`
${componentStyles}
:host {
display: inline-block;
Expand Down
3 changes: 2 additions & 1 deletion src/components/badge/badge.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { classMap } from 'lit/directives/class-map.js';
import { html } from 'lit';
import { property } from 'lit/decorators.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import styles from './badge.styles.js';
import type { CSSResultGroup } from 'lit';
Expand All @@ -16,7 +17,7 @@ import type { CSSResultGroup } from 'lit';
* @csspart base - The component's base wrapper.
*/
export default class SlBadge extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];

/** The badge's theme variant. */
@property({ reflect: true }) variant: 'primary' | 'success' | 'neutral' | 'warning' | 'danger' = 'primary';
Expand Down
3 changes: 0 additions & 3 deletions src/components/badge/badge.styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

export default css`
${componentStyles}
:host {
display: inline-flex;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/breadcrumb-item/breadcrumb-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HasSlotController } from '../../internal/slot.js';
import { html } from 'lit';
import { ifDefined } from 'lit/directives/if-defined.js';
import { property } from 'lit/decorators.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import styles from './breadcrumb-item.styles.js';
import type { CSSResultGroup } from 'lit';
Expand All @@ -26,7 +27,7 @@ import type { CSSResultGroup } from 'lit';
* @csspart separator - The container that wraps the separator.
*/
export default class SlBreadcrumbItem extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];

private readonly hasSlotController = new HasSlotController(this, 'prefix', 'suffix');

Expand Down
3 changes: 0 additions & 3 deletions src/components/breadcrumb-item/breadcrumb-item.styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

export default css`
${componentStyles}
:host {
display: inline-flex;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/breadcrumb/breadcrumb.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { html } from 'lit';
import { LocalizeController } from '../../utilities/localize.js';
import { property, query } from 'lit/decorators.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import SlIcon from '../icon/icon.component.js';
import styles from './breadcrumb.styles.js';
Expand All @@ -21,7 +22,7 @@ import type SlBreadcrumbItem from '../breadcrumb-item/breadcrumb-item.js';
* @csspart base - The component's base wrapper.
*/
export default class SlBreadcrumb extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];
static dependencies = { 'sl-icon': SlIcon };

private readonly localize = new LocalizeController(this);
Expand Down
3 changes: 0 additions & 3 deletions src/components/breadcrumb/breadcrumb.styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

export default css`
${componentStyles}
.breadcrumb {
display: flex;
align-items: center;
Expand Down
3 changes: 2 additions & 1 deletion src/components/button-group/button-group.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { html } from 'lit';
import { property, query, state } from 'lit/decorators.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import styles from './button-group.styles.js';
import type { CSSResultGroup } from 'lit';
Expand All @@ -15,7 +16,7 @@ import type { CSSResultGroup } from 'lit';
* @csspart base - The component's base wrapper.
*/
export default class SlButtonGroup extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];

@query('slot') defaultSlot: HTMLSlotElement;

Expand Down
3 changes: 0 additions & 3 deletions src/components/button-group/button-group.styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

export default css`
${componentStyles}
:host {
display: inline-block;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/button/button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ifDefined } from 'lit/directives/if-defined.js';
import { LocalizeController } from '../../utilities/localize.js';
import { property, query, state } from 'lit/decorators.js';
import { watch } from '../../internal/watch.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import SlIcon from '../icon/icon.component.js';
import SlSpinner from '../spinner/spinner.component.js';
Expand Down Expand Up @@ -38,7 +39,7 @@ import type { ShoelaceFormControl } from '../../internal/shoelace-element.js';
* @csspart spinner - The spinner that shows when the button is in the loading state.
*/
export default class SlButton extends ShoelaceElement implements ShoelaceFormControl {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];
static dependencies = {
'sl-icon': SlIcon,
'sl-spinner': SlSpinner
Expand Down
3 changes: 0 additions & 3 deletions src/components/button/button.styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

export default css`
${componentStyles}
:host {
display: inline-block;
position: relative;
Expand Down
3 changes: 2 additions & 1 deletion src/components/card/card.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { classMap } from 'lit/directives/class-map.js';
import { HasSlotController } from '../../internal/slot.js';
import { html } from 'lit';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import styles from './card.styles.js';
import type { CSSResultGroup } from 'lit';
Expand Down Expand Up @@ -28,7 +29,7 @@ import type { CSSResultGroup } from 'lit';
* @cssproperty --padding - The padding to use for the card's sections.
*/
export default class SlCard extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];

private readonly hasSlotController = new HasSlotController(this, 'footer', 'header', 'image');

Expand Down
3 changes: 0 additions & 3 deletions src/components/card/card.styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

export default css`
${componentStyles}
:host {
--border-color: var(--sl-color-neutral-200);
--border-radius: var(--sl-border-radius-medium);
Expand Down
3 changes: 2 additions & 1 deletion src/components/carousel-item/carousel-item.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { html } from 'lit';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import styles from './carousel-item.styles.js';
import type { CSSResultGroup } from 'lit';
Expand All @@ -15,7 +16,7 @@ import type { CSSResultGroup } from 'lit';
*
*/
export default class SlCarouselItem extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];

connectedCallback() {
super.connectedCallback();
Expand Down
3 changes: 0 additions & 3 deletions src/components/carousel-item/carousel-item.styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

export default css`
${componentStyles}
:host {
--aspect-ratio: inherit;
Expand Down
3 changes: 2 additions & 1 deletion src/components/carousel/carousel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { prefersReducedMotion } from '../../internal/animate.js';
import { range } from 'lit/directives/range.js';
import { waitForEvent } from '../../internal/event.js';
import { watch } from '../../internal/watch.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import SlIcon from '../icon/icon.component.js';
import styles from './carousel.styles.js';
Expand Down Expand Up @@ -47,7 +48,7 @@ import type SlCarouselItem from '../carousel-item/carousel-item.component.js';
* partially visible as a scroll hint.
*/
export default class SlCarousel extends ShoelaceElement {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];
static dependencies = { 'sl-icon': SlIcon };

/** When set, allows the user to navigate the carousel in the same direction indefinitely. */
Expand Down
3 changes: 0 additions & 3 deletions src/components/carousel/carousel.styles.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';

export default css`
${componentStyles}
:host {
--slide-gap: var(--sl-spacing-medium, 1rem);
--aspect-ratio: 16 / 9;
Expand Down
3 changes: 2 additions & 1 deletion src/components/checkbox/checkbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ifDefined } from 'lit/directives/if-defined.js';
import { live } from 'lit/directives/live.js';
import { property, query, state } from 'lit/decorators.js';
import { watch } from '../../internal/watch.js';
import componentStyles from '../../styles/component.styles.js';
import ShoelaceElement from '../../internal/shoelace-element.js';
import SlIcon from '../icon/icon.component.js';
import styles from './checkbox.styles.js';
Expand Down Expand Up @@ -40,7 +41,7 @@ import type { ShoelaceFormControl } from '../../internal/shoelace-element.js';
* @csspart form-control-help-text - The help text's wrapper.
*/
export default class SlCheckbox extends ShoelaceElement implements ShoelaceFormControl {
static styles: CSSResultGroup = styles;
static styles: CSSResultGroup = [componentStyles, styles];
static dependencies = { 'sl-icon': SlIcon };

private readonly formControlController = new FormControlController(this, {
Expand Down
5 changes: 0 additions & 5 deletions src/components/checkbox/checkbox.styles.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { css } from 'lit';
import componentStyles from '../../styles/component.styles.js';
import formControlStyles from '../../styles/form-control.styles.js';

export default css`
${componentStyles}
${formControlStyles}
:host {
display: inline-block;
}
Expand Down
Loading

0 comments on commit 02ce4db

Please sign in to comment.