Skip to content

Commit

Permalink
feat(spinner): implement spinner animation element
Browse files Browse the repository at this point in the history
chore: add correct define call to the generator template
  • Loading branch information
daenub authored Jul 24, 2024
1 parent 2f9f95f commit ba6257e
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 2 deletions.
3 changes: 1 addition & 2 deletions scripts/generate-component/templates/[namespace]-[name].js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineElement } from "../../lib/defineElement.js"
import { [Namespace][Name] } from "./[Name].js"

export { [Namespace][Name] }

defineElement("[name]", [Namespace][Name])
[Namespace][Name].define("[namespace]-[name]")
31 changes: 31 additions & 0 deletions src/components/spinner/Spinner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { html } from "lit"

import { LeuElement } from "../../lib/LeuElement.js"

import styles from "./spinner.css"

/**
* @tagname leu-spinner
* @cssprop --leu-spinner-size - The size of the spinner.
*/
export class LeuSpinner extends LeuElement {
static styles = styles

render() {
return html`
<svg
class="spinner"
fill="none"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 56 56"
role="presentation"
>
<path
d="M13.8579 13.858c7.8105-7.8105 20.4737-7.8105 28.2842 0 7.8105 7.8104 7.8105 20.4737 0 28.2842-7.8105 7.8105-20.4737 7.8105-28.2842 0-4.3487-4.3486-6.2761-10.2016-5.7824-15.8838"
stroke="currentColor"
stroke-width="3"
/>
</svg>
`
}
}
5 changes: 5 additions & 0 deletions src/components/spinner/leu-spinner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LeuSpinner } from "./Spinner.js"

export { LeuSpinner }

LeuSpinner.define("leu-spinner")
20 changes: 20 additions & 0 deletions src/components/spinner/spinner.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@keyframes leu-spinner-rotate {
from {
transform: rotate(0deg);
}

to {
transform: rotate(360deg);
}
}

:host {
color: var(--leu-color-func-cyan);
}

.spinner {
display: block;
width: var(--leu-spinner-size, 3.5rem);
height: var(--leu-spinner-size, 3.5rem);
animation: leu-spinner-rotate 1s cubic-bezier(0.49, 0.12, 0.56, 0.91) infinite;
}
29 changes: 29 additions & 0 deletions src/components/spinner/stories/spinner.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { html } from "lit"
import "../leu-spinner.js"
import { styleMap } from "lit/directives/style-map.js"

export default {
title: "Spinner",
component: "leu-spinner",
argTypes: {
color: {
control: {
type: "color",
presetColors: ["#009ee0", "#d93c1a", "#1a7f1f"],
},
},
},
}

function Template({ size, color }) {
const styles = styleMap({
color,
"--leu-spinner-size": size ? `${size}px` : null,
})
return html` <leu-spinner style=${styles}></leu-spinner> `
}

export const Regular = Template.bind({})
Regular.args = {
size: 56,
}
30 changes: 30 additions & 0 deletions src/components/spinner/test/spinner.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { html } from "lit"
import { fixture, expect } from "@open-wc/testing"

import "../leu-spinner.js"

async function defaultFixture() {
return fixture(html`<leu-spinner></leu-spinner>`)
}

describe("LeuSpinner", () => {
it("is a defined element", async () => {
const el = await customElements.get("leu-spinner")

await expect(el).not.to.be.undefined
})

it("passes the a11y audit", async () => {
const el = await defaultFixture()

await expect(el).shadowDom.to.be.accessible()
})

it("renders a svg element with a 56x56 viewbox", async () => {
const el = await defaultFixture()

const svg = el.shadowRoot.querySelector("svg")

expect(svg).to.have.attribute("viewBox", "0 0 56 56")
})
})

0 comments on commit ba6257e

Please sign in to comment.