Skip to content

Commit 1b493d5

Browse files
committed
wip: shiny-button
1 parent 36548d9 commit 1b493d5

File tree

7 files changed

+144
-13
lines changed

7 files changed

+144
-13
lines changed

s/components/button/component.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
import {html} from "lit"
3+
import {view} from "@e280/sly"
4+
import styleCss from "./style.css.js"
5+
import {foundationCss} from "../foundation.css.js"
6+
import {ShinyContext, ShinyElement} from "../framework.js"
7+
8+
export class ShinyButton extends (
9+
view(use => (context: ShinyContext) => {
10+
use.name("shiny-button")
11+
use.styles(foundationCss, context.theme, styleCss)
12+
13+
const attrs = use.attrs.spec({
14+
role: String,
15+
tabindex: Number,
16+
disabled: Boolean,
17+
hidden: Boolean,
18+
})
19+
20+
return html`
21+
<button
22+
part=button
23+
?disabled="${attrs.disabled}"
24+
?hidden="${attrs.hidden}">
25+
<slot></slot>
26+
</button>
27+
`
28+
})
29+
.component(ShinyElement)
30+
.props(el => [el.context] as const)
31+
) {}
32+

s/components/button/style.css.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
import {css} from "lit"
3+
export default css`@layer view {
4+
5+
:host {
6+
opacity: 0.8;
7+
display: contents;
8+
justify-content: center;
9+
align-items: center;
10+
11+
padding: 0.5em;
12+
border-radius: 0.2em;
13+
border: 0.1em solid currentColor;
14+
15+
cursor: pointer;
16+
color: var(--alpha);
17+
background: transparent;
18+
user-select: none;
19+
20+
outline: 3px solid yellow;
21+
}
22+
23+
/* TODO */
24+
:host-context([view="shiny-tabs"]) {
25+
outline: 3px solid red;
26+
}
27+
28+
:host(:is(:hover, :focus-visible)) { opacity: 1; }
29+
:host(:active) { opacity: 0.6; }
30+
31+
:host([disabled]) {
32+
cursor: default;
33+
color: var(--lame);
34+
opacity: var(--inactive-opacity);
35+
}
36+
37+
:host([hidden]) {
38+
display: none !important;
39+
}
40+
41+
:host([angry]) {
42+
color: var(--angry);
43+
}
44+
45+
button {
46+
all: inherit;
47+
display: inline-flex;
48+
}
49+
50+
slot {
51+
display: contents;
52+
}
53+
54+
}`
55+

s/components/raw-components.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

2+
import {ShinyButton} from "./button/component.js"
23
import {ShinyCopy} from "./copy/component.js"
34
import {ShinyDrawer} from "./drawer/component.js"
45
import {ShinyExample} from "./example/component.js"
56
import {ShinyTabs} from "./tabs/component.js"
67

78
export const rawComponents = {
9+
ShinyButton,
810
ShinyCopy,
911
ShinyDrawer,
1012
ShinyExample,

s/demo/demo.bundle.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dom.register({ShinyDemo: view.component(use => {
4242
font-style: italic;
4343
}
4444
45-
[view="shiny-tabs"] {
45+
[view="demo-tabs"] {
4646
display: flex;
4747
}
4848
}
@@ -55,7 +55,45 @@ dom.register({ShinyDemo: view.component(use => {
5555

5656
const demonstrations = [
5757
Demonstration({
58-
name: "shiny-copy",
58+
name: "button",
59+
explain: html`
60+
<p>clicky-clacky pressy button.</p>
61+
`,
62+
snippets: [
63+
[labels.html, `
64+
<shiny-button>hello</shiny-button>
65+
`],
66+
[labels.view, `
67+
ShinyButton
68+
.props()
69+
.children("hello")
70+
.render()
71+
`],
72+
[labels.css, `
73+
shiny-button {
74+
font-size: 1em;
75+
--happy: #0fa;
76+
--angry: #f50;
77+
--lame: #8888;
78+
--inactive-opacity: 0.5;
79+
}
80+
`],
81+
],
82+
content: (
83+
views.ShinyButton
84+
.props()
85+
.children("hello")
86+
.render()
87+
),
88+
style: css`
89+
.content sly-view {
90+
font-size: 2em;
91+
}
92+
`,
93+
}),
94+
95+
Demonstration({
96+
name: "copy",
5997
explain: html`
6098
<p>click-to-copy text button.</p>
6199
`,
@@ -85,7 +123,7 @@ dom.register({ShinyDemo: view.component(use => {
85123
}),
86124

87125
Demonstration({
88-
name: "shiny-drawer",
126+
name: "drawer",
89127
explain: html`
90128
<p>slide-out panel. button optional.</p>
91129
`,
@@ -160,7 +198,7 @@ dom.register({ShinyDemo: view.component(use => {
160198
}),
161199

162200
Demonstration({
163-
name: "shiny-tabs",
201+
name: "tabs",
164202
explain: html`
165203
<p>button bar. panels optional.</p>
166204
`,

s/demo/views/demonstration/view.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const Demonstration = view(use => (options: {
1414
style: CSSResultGroup
1515
}) => {
1616

17-
use.name(options.name)
17+
use.name(`demo-${options.name}`)
1818
use.styles(foundationCss, styleCss, options.style)
1919

2020
function codeblock(heading: string, code: string) {
@@ -32,14 +32,17 @@ export const Demonstration = view(use => (options: {
3232

3333
return html`
3434
<div class=meta>
35-
<h2>${options.name}</h2>
35+
<h2>shiny-${options.name}</h2>
3636
<div class=explain>${options.explain}</div>
3737
${auraViews.ShinyTabs
3838
.props()
3939
.children(html`
40-
${options.snippets.map(([label]) => html`
41-
<button>${label.button}</button>
42-
`)}
40+
${options.snippets.map(([label]) => (
41+
auraViews.ShinyButton
42+
.props()
43+
.children(label.button)
44+
.render()
45+
))}
4346
${options.snippets.map(([label, code]) => codeblock(label.text, code))}
4447
`)
4548
.render()}

s/themes/aura.css.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import {defaultCssVars, renderCssVars} from "./infra/css-vars.js"
44
export const aura = css`@layer overlay {
55
66
:host {
7-
display: block;
8-
97
${renderCssVars({
108
...defaultCssVars(),
119
})}
1210
}
1311
12+
:host([view="shiny-button"])::part(button) {
13+
padding: 0.5em;
14+
}
15+
1416
:host([view="shiny-drawer"]) {
1517
display: block;
1618
@@ -39,7 +41,7 @@ export const aura = css`@layer overlay {
3941
:host([view="shiny-tabs"]) {
4042
display: block;
4143
42-
&::part(tabs) {
44+
slot[part="tabs"] {
4345
display: flex;
4446
}
4547
}

s/themes/plain.css.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {defaultCssVars, renderCssVars} from "./infra/css-vars.js"
44
export const plain = css`@layer overlay {
55
66
:host {
7-
display: block;
87
${renderCssVars(defaultCssVars())}
98
}
109

0 commit comments

Comments
 (0)