Skip to content

Commit ad0861e

Browse files
committed
long time no see...
Lots of changes, then over 2 months away. Today I finally tweaked the CSS for the multi-state app, and I'm checking everything in.
1 parent e4c5447 commit ad0861e

39 files changed

Lines changed: 1997 additions & 713 deletions

README.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
`<input-num>` has its own [app page](https://sidewayss.github.io/html-elements/apps/input-num) because it has a lot to test and demonstrate.
88

9-
The other three share a [test/demo app](https://sidewayss.github.io/html-elements/apps/multi-state) and a [base class](#class-multistate).
9+
The other three share a [test/demo app](https://sidewayss.github.io/html-elements/apps/multi-state) and a [base class](#class-statebtn).
1010

1111
## Summary
1212
It's a collection of [autonomous](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#types_of_custom_element) custom HTML elements that can be graphically customized at the site level and/or by page. It fetches the template(s) during the page load process, and [`import.meta`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta) allows you to specify the template file or directory as [import options](#import-options).
@@ -29,12 +29,13 @@ For example, to import `<input-num>`:
2929
</head>
3030
```
3131
### File Names
32-
There are 4 elements, but only 3 root file names because `<check-box>` and `<check-tri>` share everything. The root names are:
32+
There are 4 elements and 4 root file names:
3333
- **input-num**
3434
- **state-btn**
35-
- **multi-check**
35+
- **check-box**
36+
- **check-tri**
3637

37-
Those root names apply to `src/` and `dist/` module files, template files, the sample CSS files, as well as `<template id="root-name">` when your templates into a single file.
38+
Those root names apply to `src/` and `dist/` module files, template files, the sample CSS files, as well as `<template id="root-name">` when you bundle your templates into a single file.
3839

3940
There is one more importable module, which bundles all the elements together: `elements.js`. The distributable is bundled, transpiled, and minified. The source is a barrel module with no external dependencies. *Note that you cannot use `import.meta` options with this source module because the browsers' module-load order prevents it.*
4041

@@ -103,7 +104,7 @@ A quick glossary entry of note: A [boolean attribute](https://developer.mozilla.
103104
These classes manage common attributes/properties and behaviors across elements. All the attributes/properties listed are inherited by the sub-classes.
104105
105106
### `class BaseElement extends HTMLElement`
106-
`BaseElement` is the top level class. It is the parent class for `InputNum` and `MultiState`. See `base-element.js`.` It manages two global DOM attributes/properties:
107+
`BaseElement` is the top level class. It is the parent class for `InputNum` and `StateBtn`. See `base-element.js`.` It manages two global DOM attributes/properties:
107108
- `disabled/disabled`
108109
- `tabindex/tabIndes`
109110
@@ -117,25 +118,25 @@ This is because the DOM runs `attributeChangedCallback()` in a FIFO queue and wh
117118
118119
*Also note:* Though it's allowed, setting `tabindex` to anything other than `0` or `-1` is sternly [recommended against by MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex) (*scroll down the page to the first Warning block*).
119120
120-
### `class MultiState`
121-
`MultiState` (`multi-state.js`) is the parent class for `<state-btn>` and `MultiCheck`.
121+
### `class StateBtn`
122+
`StateBtn` is the class for `<state-btn>` and the parent of `CheckBase`.
122123
- `key-codes` / `keyCodes` - Internally it's a Set of [keycodes](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_code_values) that act like a mouse click. It converts `click` and `keyup` to `change` for compatibility with `<input type="checkbox">`. The attribute value is an array in JSON format. The property returns an array, and accepts anything array-like, including Set.
123124
124125
There is no `input` event, just `change`. For these types of `<input>` they're the same anyway. If you desire it for compatibility reasons, submit an issue or a pull request.
125126
126-
### `class MultiCheck`
127-
`MultiCheck` (`multi-check.js`) is the parent class for `<check-box>` and `<check-tri>`.
127+
### `class CheckBase`
128+
`CheckBase` (`check-base.js`) is the parent class for `<check-box>` and `<check-tri>`.
128129
- `label` / `label` contains the `innerHTML` for the built-in label element.
129130
- `labelElement` (read-only property) returns the shadowDOM element with `id="label"`.
130131
- `key-codes` defaults to `["Space"]`.
131132
132133
## `<check-box>`
133134
I created `<check-box>` because I needed `<check-tri>` and I wanted all my checkboxes to look and act alike. It's the same as `<input type="checkbox">` except:
134-
- The label is built-in through the `label` attribute (see `class MultiCheck` directly above here).
135+
- The label is built-in through the `label` attribute (see `class CheckBase` directly above here).
135136
- It has a JavaScript `value` property that is identical to `checked`, in order to normalize it with other types of `<input>` and elements like `<select>` when iterating over or switching through elements.
136137
- The checkbox graphics are in a separate template file, in SVG.
137138
138-
## `<check-tri>`
139+
## `<check-trie>`
139140
`<input type="checkbox">` has an `indeterminate` property (not an attribute) that is independent from `checked`. I don't have a use for that. I needed a third, "indeterminate" value in addition to, and mutually exclusive from, `true` and `false`. I wanted that value to cause `checked` to fall back to a user-determined default boolean value. So `checked` remains boolean, but `value` can be `true`, `false`, or `null`. It's `null`, not `undefined`, because that's what `getAttribute()` returns when an attribute is unset.
140141
141142
To set `value` as an attribute, I use `"1"` for `true` and you must use `""` for `false`.
@@ -145,7 +146,7 @@ To set `value` as an attribute, I use `"1"` for `true` and you must use `""` for
145146
- `show-default` / `showDefault` is a boolean that shows or hides the default value as a read-only box to the left.
146147
147148
### multi-check.html
148-
`<check-box>` and `<check-tri>` share a template file. The built-in template is potentially reusable because the shapes are simple and they are 100% externally styleable with `::part`. This is the `<template>`:
149+
`<check-box>` and `<check-tri>` share a template file. The built-in template is potentially reusable because the shapes are simple and they are externally styleable with `::part`. This is the `<template>`:
149150
```html
150151
<template>
151152
<svg id="shapes" part="shapes" viewbox="0 0 18 15" width="18" height="15">
@@ -183,7 +184,7 @@ The other optional element with an `id` is `#false`. The built-in template doesn
183184
184185
The `part` attributes are all optional.
185186
186-
__NOTE:__ With this template, the element is a flex container, relying on the default `flex-direction:row`. I find that `align-items:center` works best for this combination of shapes, font, and font size because the box's bottom line aligns with the font baseline:
187+
__NOTE:__ With this template, the element is a flex container, relying on the default `flex-direction:row`.
187188
```css
188189
check-box, check-tri {
189190
display: flex;
@@ -300,7 +301,7 @@ Property name same as attribute. String as attribute / Number as property.
300301
301302
#### Behavior
302303
- `blur-cancel` / `blurCancel` is a boolean that cancels keyboard input when the user blurs the element via `Tab`, `Shift+Tab`, or by clicking elsewhere on the page. The default behavior is to confirm the value. Does not affect the behavior of the <Enter> or <Esc> keys or the OK or Cancel buttons.
303-
- `no-keys` / `keyboards` disables/enables keyboard input. Combining it with `no-spin` effectively disables the element.
304+
- `no-keys` / `keyboards` disables/enables direct keyboard input, but allows up/down arrow keys for spinning. Combining it with `no-spin` effectively disables the element.
304305
- `no-resize` / `autoResize` used to disable the `resize()` function while loading the page or setting a batch of element properties.
305306
306307
#### Spinner
@@ -359,7 +360,7 @@ The `validate` property allows you to insert your own validation and/or transfor
359360
To indicate an invalid value, return `false`. Otherwise return the value itself, transformed or not. Transforms are for those rare occasions when you want to round to the nearest prime number, or whatever transformation or restriction that can't be defined solely by `max` and `min`.
360361
361362
### Styling
362-
You can obviously style the element itself, but you can also style some of its parts via the `::part` pseudo-element. Remember that `::part` overrides the shadow DOM elements' style. You must use `!important` if you want to override `::part`.
363+
You can obviously style the element itself, but you can also style its parts via the `::part` pseudo-element. Remember that `::part` overrides the shadow DOM elements' style. You must use `!important` if you want to override `::part`.
363364
364365
The available parts:
365366
- `input` is the `<input type="text">`.
@@ -399,6 +400,8 @@ for (const elm of document.getElementsByTagName("input-num")) {
399400
}
400401
```
401402
403+
__NOTE:__ If you set `no-spin` and `no-confirm`, you should probably also set the element's `tabindex="-1"`, and put any border or padding on `::part(input)` not the element itself. Otherwise the outer element will still be in the tab order or clickable for focus, and that serves no purpose with those two attributes set.
404+
402405
### input-num.html
403406
The core of the template is a flex `<div>`, with three children:
404407
- `<input type="text" id="input" part="input"/>` - the text input

apps/common.css

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
@font-face {
22
font-family:"Roboto Mono";
3-
font-weight:400;
3+
font-weight:400 500 900;
4+
font-style:normal;
45
src:url("/fonts/RobotoMono.ttf") format("truetype");
56
}
67
* {
78
font-family:"Roboto Mono", monospace;
89
font-size:1rem;
9-
color:#272727;
10+
color:#171717;
11+
}
12+
body {
13+
align-items:center;
14+
margin:0;
1015
}
1116
p {
1217
font-family:sans-serif;
@@ -21,9 +26,10 @@ button {
2126
width: 1rem;
2227
height: 1rem;
2328
padding:0;
24-
margin: 0 0.375rem 0.1875rem 0.75rem;
29+
margin: 0 0.25rem 0.1875rem 0.75rem;
2530
border:none;
2631
background-image:url("clipboard.png");
32+
background-color:transparent;
2733
background-size:contain;
2834
background-repeat:no-repeat;
2935
}
@@ -37,13 +43,22 @@ select {
3743
background-color:white;
3844
border-color:#0002;
3945
}
46+
select:hover {
47+
border-color:#000;
48+
}
4049
select:disabled, .disabled {
4150
opacity:1;
4251
color:gray;
4352
background-color:transparent;
4453
}
4554

46-
.info { margin:0 0 0 0.25rem }
55+
.info {
56+
margin:0;
57+
background-color:#FEFEFD;
58+
border:1px solid #FEFEFD;
59+
border-left:none;
60+
padding:0.0625rem 0.125rem 0.125rem 0.25rem;
61+
}
4762
.warning { color:#800; }
4863
.italic { font-style:italic }
4964
.copied {
@@ -62,18 +77,19 @@ select:disabled, .disabled {
6277
align-items:center;
6378
margin-top:0.125rem;
6479
}
80+
.mt1-2,
6581
div.mt1-2 { margin-top: 0.5rem }
6682
div.mb3-16 { margin-bottom:0.1875rem }
83+
div.mb3-8 { margin-bottom:0.375rem }
6784
div.between { justify-content:space-between; }
68-
.chk-val { margin-top:0.25rem }
69-
.separator {
85+
div.chk-val { margin-top:0.25rem }
86+
div.separator {
7087
color:#787;
7188
margin-bottom:0.5rem;
7289
}
7390
div.header {
7491
align-items:stretch;
7592
align-self: stretch;
76-
margin-right:0.125rem;
7793
}
7894
#html, #script, .html {
7995
font-family:monospace;

apps/input-num/index.css

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,39 @@
1515
font-style:italic;
1616
src:url("/fonts/RobotoMono.ttf") format("truetype");
1717
}
18-
@media (height < 340px) {
19-
* { font-family:monospace; }
18+
@media (width <= 500px) {
19+
body { background-color:#171717 !important }
20+
}
21+
@media (width < 340px) {
22+
* { font-size: 0.9375rem }
2023
}
2124
@media (hover:none) {
2225
input-num::part(buttons) { display:none }
2326
}
24-
select { margin-left: 0.25rem; }
25-
check-box { margin-right:1rem }
27+
body {
28+
background-color:aliceblue;
29+
}
30+
select { margin-left: 0.25rem; }
31+
check-box { margin-right:1rem; }
32+
#autoAlign, /* exceptions to check-box margin */
2633
#accounting,
27-
#keyboards { margin-right:0 } /* exceptions to check-box margin */
34+
#keyboards,
35+
#fontStyle { margin-right:0 }
36+
#anyDecimal,
37+
#blurCancel { margin-left: 1rem }
2838

2939
#max, #min, #step, #delay, #interval {
3040
text-align:right
41+
}
42+
#controls {
43+
align-items:flex-start;
44+
margin: 0.75rem 0;
45+
padding:0.8125rem 0.75rem 0.6875rem 1rem;
46+
background-color:#FEFEFD;
47+
box-shadow: 1px 0 4px #171717 inset;
48+
border: 2px solid #171717;
49+
border-radius:0.75rem;
50+
}
51+
.center {
52+
align-self:center;
3153
}

apps/input-num/index.html

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,43 @@
88
<link rel="stylesheet" href="../common.css"/>
99
<link rel="stylesheet" href="index.css"/>
1010
<script type="module">
11-
import "../../input-num.js?templateDir=/html-templates/";
11+
import "../../input-num.js?directory=/html-templates/";
1212
</script>
1313
<script type="module">
14-
import "../../multi-check.js?templateDir=/html-templates/";
14+
import "../../check-box.js?path=/html-templates/multi-check.html";
1515
</script>
1616
<script src="index.js" type="module"></script>
1717
</head>
18-
<body class="col" style="align-items:center; background-color:#F9F9F9;">
19-
<input-num id="number"></input-num>
20-
<div class="col" style="align-items:flex-start;">
21-
<div class="row mt1-2 mb3-16">
22-
<label for="autoWidth" style="margin-right:0.75rem">Auto:</label>
23-
<check-box id="autoWidth" label="Width" checked disabled
24-
title="Auto-size width, disabled by infinite max or min value">
25-
</check-box>
26-
<check-box id="autoAlign" label="Align" checked
27-
title="Auto-align left or right, and auto-pad-right">
18+
<body class="col">
19+
<div class="col" id="controls">
20+
<input-num id="number" class="center" value="1234567890"></input-num> <!-- defaults to infinite min-max range -->
21+
<div class="row mt1-2 mb3-8">
22+
<label for="autoResize" style="margin-right:0.5rem">auto:</label>
23+
<check-box id="autoResize" label="Resize" checked
24+
title="Auto-resize upon any relevant property change">
2825
</check-box>
2926
<check-box id="autoScale" label="Scale" checked
3027
title="Auto-scale the buttons to fit the element size">
3128
</check-box>
29+
<check-box id="autoAlign" label="Align" checked
30+
title="Auto-align-right, auto-pad-right">
31+
</check-box>
3232
</div>
3333
<div class="row">
34-
<label for="max">Max:&nbsp;&nbsp;&nbsp;</label>
34+
<label for="max">Max:</label>
3535
<select id="max" class="attr"></select>
36+
<label for="width" style="margin-left:1rem">Width:</label>
37+
<select id="width" class="attr">
38+
<option>auto</option>
39+
<option>none</option>
40+
<option>200px</option>
41+
<option>10rem</option>
42+
<option>12rch</option>
43+
</select>
44+
</div>
45+
<div class="row">
46+
<label for="min">Min:</label>
47+
<select id="min"></select>
3648
<p class="info warning italic"></p>
3749
</div>
3850
<div class="row">
@@ -74,7 +86,7 @@
7486
</check-box>
7587
</div>
7688
<div class="row">
77-
<label for="step">Step:&nbsp;&nbsp;&nbsp;&nbsp;</label>
89+
<label for="step">Step:&nbsp;</label>
7890
<select id="step">
7991
<option value="">auto</option>
8092
<option>1000</option>
@@ -86,10 +98,10 @@
8698
<option >1</option>
8799
<option >0.5</option>
88100
</select>
89-
<p class="info" style="font-family:Roboto Mono"></p>
101+
<p class="info" style="font-family:Roboto Mono; margin-left:0.3125rem;"></p>
90102
</div>
91103
<div class="row">
92-
<label for="delay">Delay:&nbsp;&nbsp;&nbsp;</label>
104+
<label for="delay">Delay:&nbsp;&nbsp;</label>
93105
<select id="delay"></select>
94106
</div>
95107
<div class="row">
@@ -117,14 +129,20 @@
117129
<option value="500">500ms</option>
118130
</select>
119131
</div>
120-
<div class="row mt1-2 mb3-16">
121-
<check-box id="blurCancel" label="onblur() &nbsp;= cancel input"
122-
title="Cancel instead of confirming when tabbing out of the element or clicking elsewhere on the page.">
132+
<div class="row mb3-16 mt1-2">
133+
<check-box id="showButtons" label="showButtons"
134+
title="Always display the spinner and/or confirm buttons. Designed for units = none.">
135+
</check-box>
136+
<check-box id="anyDecimal" label="anyDecimal"
137+
title="Allows the user to input either comma ',' or period '.' as the decimal marker">
123138
</check-box>
124139
</div>
125140
<div class="row mb3-16">
126-
<check-box id="anyDecimal" label="anyDecimal: comma or period"
127-
title='Allows the user to input either comma "," or period "." as the decimal marker'>
141+
<check-box id="trimRight" label="trimRight "
142+
title="When units.width < buttons.width, trims and pads the element width.">
143+
</check-box>
144+
<check-box id="blurCancel" label="blurCancel"
145+
title="Cancel instead of confirming when tabbing out of the element or clicking elsewhere on the page.">
128146
</check-box>
129147
</div>
130148
<!-------------->
@@ -134,7 +152,7 @@
134152
</div>
135153
<div class="row">
136154
<label for="fontSize">size:</label>
137-
<select id="fontSize" style="margin-right:0.5rem">
155+
<select id="fontSize" style="margin-right:0.875rem">
138156
<option>8px</option>
139157
<option>12px</option>
140158
<option selected>16px</option>
@@ -146,7 +164,7 @@
146164
<option>32px</option>
147165
<option>48px</option>
148166
</select>
149-
<check-box id="fontWeight" label="bold"
167+
<check-box id="fontWeight" label="bold" style="margin-right:0.875rem"
150168
title="Affects units width with variable width-fonts">
151169
</check-box>
152170
<check-box id="fontStyle" label="italic"

0 commit comments

Comments
 (0)