-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from hotosm/feat/shoelace
Extend composite components from shoelace web components
- Loading branch information
Showing
29 changed files
with
1,328 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,24 @@ | ||
import "./theme/hot.css"; | ||
import { Button as ButtonImport } from "./button/Button"; | ||
export { Button } from "./button/Button"; | ||
import '@shoelace-style/shoelace/dist/themes/light.css'; | ||
import '@shoelace-style/shoelace/dist/themes/dark.css'; | ||
|
||
import '@shoelace-style/shoelace/dist/components/button/button.js'; | ||
import '@shoelace-style/shoelace/dist/components/button-group/button-group.js'; | ||
import '@shoelace-style/shoelace/dist/components/icon/icon.js'; | ||
import '@shoelace-style/shoelace/dist/components/tooltip/tooltip.js'; | ||
|
||
import { setBasePath } from '@shoelace-style/shoelace/dist/utilities/base-path.js'; | ||
|
||
import { Toolbar as ToolbarImport } from "./toolbar/Toolbar"; | ||
|
||
// Set the base path to the folder you copied Shoelace's assets to | ||
setBasePath('/shoelace'); | ||
|
||
// import { Radio as RadioImport } from "./radio/Radio"; | ||
|
||
// export { Card } from "@/card/Card.js"; | ||
// export { Dropdown } from "@/dropdown/Dropdown.js"; | ||
// export { Toggle } from "@/toggle/Toggle.js"; | ||
|
||
customElements.define("hot-button", ButtonImport); | ||
customElements.define("hot-toolbar", ToolbarImport); | ||
// customElements.define("hot-radio", RadioImport); |
22 changes: 9 additions & 13 deletions
22
components/button/Button.stories.ts → components/toolbar/Toolbar.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,30 @@ | ||
import type { Meta, StoryObj } from "@storybook/web-components"; | ||
import "./Button"; | ||
import "./Toolbar"; | ||
import { html } from "lit"; | ||
|
||
const meta: Meta = { | ||
component: "hot-button", | ||
component: "hot-toolbar", | ||
}; | ||
export default meta; | ||
|
||
export const Template: StoryObj = { | ||
args: { | ||
intent: "primary", | ||
disabled: false, | ||
tooltipPosition: "top", | ||
}, | ||
argTypes: { | ||
intent: { | ||
options: ["primary", "secondary"], | ||
tooltipPosition: { | ||
options: ["top", "bottom", "left", "right"], | ||
control: { | ||
type: "select", | ||
}, | ||
}, | ||
}, | ||
render: (args) => { | ||
return html` | ||
<hot-button | ||
intent=${args.intent} | ||
?disabled=${args.disabled} | ||
@click=${() => {alert("Button Clicked")}} | ||
> | ||
Button | ||
</hot-button> | ||
<hot-toolbar | ||
tooltip-position="${args.tooltipPosition}" | ||
@hot-redo-click=${() => {alert("Redo Clicked")}} | ||
></hot-toolbar> | ||
`; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { LitElement, css, html, unsafeCSS } from "lit"; | ||
import { property } from "lit/decorators.js"; | ||
import reset from "../tailwind-reset"; | ||
import { cva } from "class-variance-authority"; | ||
|
||
const toolbarStyle = cva( | ||
"some-css-var", | ||
{ | ||
variants: { | ||
someProperty: { | ||
true: "some-css-var", | ||
false: "some-css-var", | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
export class Toolbar extends LitElement { | ||
@property() name = "hot-toolbar"; | ||
|
||
/** Change the position of the tooltips relative to buttons. */ | ||
@property({ type: String, attribute: "tooltip-position" }) tooltipPosition = "top"; | ||
|
||
static styles = [ | ||
css` | ||
@unocss-placeholder; | ||
`, | ||
unsafeCSS(reset), | ||
]; | ||
|
||
// class=${toolbarStyle({ | ||
// someProperty: this.someProperty, | ||
// })} | ||
protected render() { | ||
return html` | ||
<div class="button-group-toolbar"> | ||
${this.renderButtonGroup('History', [ | ||
{ content: 'Undo', icon: 'arrow-counterclockwise', label: 'Undo', action: this.undo }, | ||
{ content: 'Redo', icon: 'arrow-clockwise', label: 'Redo', action: this.redo } | ||
])} | ||
${this.renderButtonGroup('Formatting', [ | ||
{ content: 'Bold', icon: 'type-bold', label: 'Bold', action: this.bold }, | ||
{ content: 'Italic', icon: 'type-italic', label: 'Italic', action: this.italic }, | ||
{ content: 'Underline', icon: 'type-underline', label: 'Underline', action: this.underline } | ||
])} | ||
${this.renderButtonGroup('Alignment', [ | ||
{ content: 'Align Left', icon: 'justify-left', label: 'Align Left', action: this.alignLeft }, | ||
{ content: 'Align Center', icon: 'justify', label: 'Align Center', action: this.alignCenter }, | ||
{ content: 'Align Right', icon: 'justify-right', label: 'Align Right', action: this.alignRight } | ||
])} | ||
</div> | ||
`; | ||
} | ||
|
||
private renderButtonGroup(label: string, buttons: Array<{ content: string, icon: string, label: string, action?: (e: MouseEvent) => void }>) { | ||
return html` | ||
<sl-button-group label=${label}> | ||
${buttons.map(button => this.renderButton(button))} | ||
</sl-button-group> | ||
`; | ||
} | ||
|
||
private renderButton({ content, icon, label, action }: { content: string, icon: string, label: string, action?: (e: MouseEvent) => void }) { | ||
return html` | ||
<sl-tooltip content=${content} placement="${this.tooltipPosition}"> | ||
<sl-button @click=${action ?? (() => {})}><sl-icon name=${icon} label=${label}></sl-icon></sl-button> | ||
</sl-tooltip> | ||
`; | ||
} | ||
|
||
private readonly undo = (e: MouseEvent) => { | ||
// As the original event is also named 'click' | ||
// stop propagation of the original event | ||
e.stopPropagation(); | ||
this.dispatchEvent(new Event("hot-undo-click")); | ||
} | ||
|
||
private readonly redo = (e: MouseEvent) => { | ||
e.stopPropagation(); | ||
this.dispatchEvent(new Event("hot-redo-click")); | ||
} | ||
|
||
private readonly bold = (e: MouseEvent) => { | ||
e.stopPropagation(); | ||
this.dispatchEvent(new Event("hot-bold-click")); | ||
} | ||
|
||
private readonly italic = (e: MouseEvent) => { | ||
e.stopPropagation(); | ||
this.dispatchEvent(new Event("hot-italic-click")); | ||
} | ||
|
||
private readonly underline = (e: MouseEvent) => { | ||
e.stopPropagation(); | ||
this.dispatchEvent(new Event("hot-underline-click")); | ||
} | ||
|
||
private readonly alignLeft = (e: MouseEvent) => { | ||
e.stopPropagation(); | ||
this.dispatchEvent(new Event("hot-leftalign-click")); | ||
} | ||
|
||
private readonly alignCenter = (e: MouseEvent) => { | ||
e.stopPropagation(); | ||
this.dispatchEvent(new Event("hot-centeralign-click")); | ||
} | ||
|
||
private readonly alignRight = (e: MouseEvent) => { | ||
e.stopPropagation(); | ||
this.dispatchEvent(new Event("hot-rightalign-click")); | ||
} | ||
} | ||
|
||
export default Toolbar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# hot-toolbar | ||
|
||
## Properties | ||
|
||
| Property | Attribute | Type | Default | Description | | ||
|-------------------|--------------------|----------|---------------|--------------------------------------------------| | ||
| `name` | `name` | `string` | "hot-toolbar" | | | ||
| `tooltipPosition` | `tooltip-position` | `string` | "top" | Change the position of the tooltips relative to buttons. | | ||
|
||
## Events | ||
|
||
| Event | | ||
|-------------------------| | ||
| `hot-bold-click` | | ||
| `hot-centeralign-click` | | ||
| `hot-italic-click` | | ||
| `hot-leftalign-click` | | ||
| `hot-redo-click` | | ||
| `hot-rightalign-click` | | ||
| `hot-underline-click` | | ||
| `hot-undo-click` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.