@hotosm/ui 0.2.0-a6 → 0.2.0-a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -14
- package/components/Header.d.ts +16 -0
- package/components/Header.js +150 -0
- package/components/index.d.ts +4 -0
- package/components/index.js +6 -0
- package/package.json +14 -3
- package/react/Button.d.ts +2 -0
- package/react/Button.js +14 -0
- package/react/Header.d.ts +2 -0
- package/react/Header.js +11 -0
- package/react/Toolbar.d.ts +2 -0
- package/react/Tracking.d.ts +2 -0
- package/react/index.d.ts +4 -0
- package/react/index.js +6 -0
- package/react/HotToolbar.d.ts +0 -12
- package/react/HotTracking.d.ts +0 -6
- /package/react/{HotToolbar.js → Toolbar.js} +0 -0
- /package/react/{HotTracking.js → Tracking.js} +0 -0
package/README.md
CHANGED
|
@@ -59,35 +59,43 @@ pnpm install @hotosm/ui
|
|
|
59
59
|
|
|
60
60
|
## Usage
|
|
61
61
|
|
|
62
|
-
### HTML / HTMX
|
|
62
|
+
### CDN (HTML / HTMX)
|
|
63
63
|
|
|
64
64
|
```html
|
|
65
|
-
// Import
|
|
65
|
+
// Import Shoelace dependency
|
|
66
|
+
<link
|
|
67
|
+
rel="stylesheet"
|
|
68
|
+
href="https://cdn.jsdelivr.net/npm/@shoelace-style
|
|
69
|
+
/shoelace@2.15.1/cdn/themes/light.css" />
|
|
66
70
|
<script
|
|
67
71
|
type="module"
|
|
68
|
-
src="https://
|
|
72
|
+
src="https://cdn.jsdelivr.net/npm/@shoelace-style/
|
|
73
|
+
shoelace@2.15.1/cdn/shoelace-autoloader.js"
|
|
69
74
|
></script>
|
|
70
75
|
|
|
71
|
-
// Import the styles (or
|
|
76
|
+
// Import the components & styles (or add your own styling)
|
|
72
77
|
<link
|
|
73
78
|
rel="stylesheet"
|
|
74
|
-
href="https://s3.amazonaws.com/hotosm-ui/latest/theme/
|
|
79
|
+
href="https://s3.amazonaws.com/hotosm-ui/latest/theme/styles.css"
|
|
75
80
|
/>
|
|
81
|
+
<script
|
|
82
|
+
type="module"
|
|
83
|
+
src="https://s3.amazonaws.com/hotosm-ui/latest/components/Button.js"
|
|
84
|
+
></script>
|
|
76
85
|
|
|
77
86
|
<div>
|
|
78
87
|
<hot-button disabled> </hot-button>
|
|
79
88
|
</div>
|
|
80
89
|
```
|
|
81
90
|
|
|
91
|
+
> Using the Shoelace autoloader will lazy load only the components you use.
|
|
92
|
+
|
|
82
93
|
See the docs for more [usage examples](https://hotosm.github.io/ui/usage/).
|
|
83
94
|
|
|
84
|
-
>
|
|
85
|
-
>
|
|
86
|
-
> extra.js will contain additional wrapper components.
|
|
87
|
-
>
|
|
88
|
-
> There should be versioning of the components, plus a /latest/ version too.
|
|
95
|
+
> Components are versioned under subdirectories, with /latest/ tracking the
|
|
96
|
+
> `main` branch, plus versioned releases.
|
|
89
97
|
|
|
90
|
-
###
|
|
98
|
+
### ES6 Imports (most frameworks)
|
|
91
99
|
|
|
92
100
|
Install your required version with a pin, or latest:
|
|
93
101
|
|
|
@@ -96,7 +104,80 @@ pnpm install @hotosm/ui
|
|
|
96
104
|
```
|
|
97
105
|
|
|
98
106
|
```js
|
|
99
|
-
|
|
107
|
+
<script>
|
|
108
|
+
import '@hotosm/ui/theme/styles.css'
|
|
109
|
+
import '@hotosm/ui/components/Button'
|
|
110
|
+
</script>
|
|
111
|
+
|
|
112
|
+
<hot-button disabled></hot-button>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
> Note that web components must always have a closing tag.
|
|
116
|
+
|
|
117
|
+
#### Importing Icons
|
|
118
|
+
|
|
119
|
+
The icon pack for Shoelace must be imported to display in components.
|
|
120
|
+
|
|
121
|
+
There are two options:
|
|
122
|
+
|
|
123
|
+
##### 1. CDN Assets
|
|
124
|
+
|
|
125
|
+
Just add the Shoelace icons via CDN in your HTML file:
|
|
126
|
+
|
|
127
|
+
```html
|
|
128
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@shoelace-style
|
|
129
|
+
/shoelace@2.15.1/cdn/themes/light.css" />
|
|
130
|
+
|
|
131
|
+
// Or dark
|
|
132
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@shoelace-style
|
|
133
|
+
/shoelace@2.15.1/cdn/themes/dark.css" />
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
##### 2. Bundle Assets Yourself
|
|
137
|
+
|
|
138
|
+
- Add Shoelace as a `peerDependency` and to your `package.json`:
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
"peerDependencies": {
|
|
142
|
+
"@shoelace-style/shoelace": "^2.15.1"
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
- Also add `vite-plugin-static-copy` as a devDependency:
|
|
147
|
+
`pnpm install -D vite-plugin-static-copy`
|
|
148
|
+
- Add to your `vite.config.ts`:
|
|
149
|
+
|
|
150
|
+
```js
|
|
151
|
+
import { viteStaticCopy } from 'vite-plugin-static-copy';
|
|
152
|
+
|
|
153
|
+
export default defineConfig({
|
|
154
|
+
plugins: [
|
|
155
|
+
viteStaticCopy({
|
|
156
|
+
targets: [
|
|
157
|
+
{
|
|
158
|
+
src: 'node_modules/@shoelace-style/shoelace/dist/assets',
|
|
159
|
+
dest: ''
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
}),
|
|
163
|
+
],
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
- Now the Shoelace assets will be bundled with your dist, under `/shoelace`.
|
|
167
|
+
|
|
168
|
+
#### React
|
|
169
|
+
|
|
170
|
+
Versions of React below v19 require a specific 'wrapper' component to use the
|
|
171
|
+
web components.
|
|
172
|
+
|
|
173
|
+
Use these instead of the standard `@hotosm/ui/components/xxx`:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
pnpm install @hotosm/ui
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
```js
|
|
180
|
+
import { Button } from '@hotosm/ui/react/Button'
|
|
100
181
|
|
|
101
182
|
const HomePage = ({}) => {
|
|
102
183
|
return (
|
|
@@ -104,8 +185,7 @@ const HomePage = ({}) => {
|
|
|
104
185
|
<div
|
|
105
186
|
...
|
|
106
187
|
>
|
|
107
|
-
<
|
|
108
|
-
</hot-button>
|
|
188
|
+
<Button disabled />
|
|
109
189
|
</div>
|
|
110
190
|
</div>
|
|
111
191
|
);
|
|
@@ -113,3 +193,23 @@ const HomePage = ({}) => {
|
|
|
113
193
|
|
|
114
194
|
export default HomePage;
|
|
115
195
|
```
|
|
196
|
+
|
|
197
|
+
## Using Extra Shoelace Components
|
|
198
|
+
|
|
199
|
+
The UI library is not comprehensive & you may wish to use additional components
|
|
200
|
+
from Shoelace in your app.
|
|
201
|
+
|
|
202
|
+
Ideally you should install the same version of @shoelace-style/shoelace as this
|
|
203
|
+
library.
|
|
204
|
+
|
|
205
|
+
To determine which version:
|
|
206
|
+
|
|
207
|
+
- View the
|
|
208
|
+
[@hotosm/ui](https://www.npmjs.com/package/@hotosm/ui?activeTab=versions)
|
|
209
|
+
package on npmjs.com.
|
|
210
|
+
- Select the version you are using.
|
|
211
|
+
- Go to the `Code` tab, then open the `package.json` file.
|
|
212
|
+
- The version of shoelace used should be in the `dependencies` section.
|
|
213
|
+
|
|
214
|
+
If you are using a bundler, you must bundle the (icon) assets yourself,
|
|
215
|
+
as described above.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import "../theme/hot.css";
|
|
2
|
+
import '@shoelace-style/shoelace/dist/themes/light.css';
|
|
3
|
+
import '@shoelace-style/shoelace/dist/themes/dark.css';
|
|
4
|
+
import '@shoelace-style/shoelace/dist/components/icon-button/icon-button.js';
|
|
5
|
+
import '@shoelace-style/shoelace/dist/components/tab-panel/tab-panel.js';
|
|
6
|
+
import '@shoelace-style/shoelace/dist/components/tab/tab.js';
|
|
7
|
+
import { LitElement } from "lit";
|
|
8
|
+
export declare class Header extends LitElement {
|
|
9
|
+
name: string;
|
|
10
|
+
title: string;
|
|
11
|
+
logo: string | URL;
|
|
12
|
+
drawer: boolean;
|
|
13
|
+
static styles: import("lit").CSSResult[];
|
|
14
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
15
|
+
}
|
|
16
|
+
export default Header;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import "../theme/hot.css";
|
|
8
|
+
import '@shoelace-style/shoelace/dist/themes/light.css';
|
|
9
|
+
import '@shoelace-style/shoelace/dist/themes/dark.css';
|
|
10
|
+
import '@shoelace-style/shoelace/dist/components/icon-button/icon-button.js';
|
|
11
|
+
import '@shoelace-style/shoelace/dist/components/tab-panel/tab-panel.js';
|
|
12
|
+
import '@shoelace-style/shoelace/dist/components/tab/tab.js';
|
|
13
|
+
import { LitElement, css, html } from "lit";
|
|
14
|
+
import { property } from "lit/decorators.js";
|
|
15
|
+
const hotLogo = new URL('../theme/logo.png', import.meta.url);
|
|
16
|
+
// import { cva } from "class-variance-authority";
|
|
17
|
+
// const headerStyle = cva(
|
|
18
|
+
// "some-css-var",
|
|
19
|
+
// {
|
|
20
|
+
// variants: {
|
|
21
|
+
// someProperty: {
|
|
22
|
+
// true: "some-css-var",
|
|
23
|
+
// false: "some-css-var",
|
|
24
|
+
// },
|
|
25
|
+
// },
|
|
26
|
+
// },
|
|
27
|
+
// );
|
|
28
|
+
export class Header extends LitElement {
|
|
29
|
+
constructor() {
|
|
30
|
+
super(...arguments);
|
|
31
|
+
this.name = "hot-header";
|
|
32
|
+
this.title = '';
|
|
33
|
+
this.logo = hotLogo;
|
|
34
|
+
this.drawer = true;
|
|
35
|
+
}
|
|
36
|
+
// class=${headerStyle({
|
|
37
|
+
// someProperty: this.someProperty,
|
|
38
|
+
// })}
|
|
39
|
+
render() {
|
|
40
|
+
const logoSrc = typeof this.logo === 'string' || this.logo instanceof URL ? (typeof this.logo === 'string' ? this.logo : this.logo.href) : '';
|
|
41
|
+
return html `
|
|
42
|
+
<header>
|
|
43
|
+
|
|
44
|
+
${(logoSrc.length > 0) ? html `
|
|
45
|
+
<div id="logo-block">
|
|
46
|
+
<img id="logo" src="${this.logo}" alt="Logo">
|
|
47
|
+
</div>
|
|
48
|
+
` : null}
|
|
49
|
+
|
|
50
|
+
${(this.title.length > 0) ? html `
|
|
51
|
+
<h1>${this.title}</h1>
|
|
52
|
+
` : null}
|
|
53
|
+
|
|
54
|
+
<sl-tab-group>
|
|
55
|
+
<sl-tab slot="nav" panel="projects">Explore Projects</sl-tab>
|
|
56
|
+
<sl-tab slot="nav" panel="organisations">Manage Organizations</sl-tab>
|
|
57
|
+
</sl-tab-group>
|
|
58
|
+
|
|
59
|
+
${this.drawer ? html `
|
|
60
|
+
<div id="drawer-block" style="font-size: 32px;">
|
|
61
|
+
<sl-icon-button name="list" label="drawer-open"></sl-icon-button>
|
|
62
|
+
</div>
|
|
63
|
+
` : null}
|
|
64
|
+
|
|
65
|
+
</header>
|
|
66
|
+
`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
Header.styles = [
|
|
70
|
+
css `
|
|
71
|
+
@unocss-placeholder;
|
|
72
|
+
`,
|
|
73
|
+
// unsafeCSS(reset),
|
|
74
|
+
css `
|
|
75
|
+
header {
|
|
76
|
+
display: flex;
|
|
77
|
+
justify-content: space-between;
|
|
78
|
+
align-items: center;
|
|
79
|
+
background: var(--app-color-primary);
|
|
80
|
+
color: white;
|
|
81
|
+
padding: 12px;
|
|
82
|
+
padding-top: 4px;
|
|
83
|
+
|
|
84
|
+
position: fixed;
|
|
85
|
+
left: 0;
|
|
86
|
+
top: 0;
|
|
87
|
+
height: 50px;
|
|
88
|
+
width: 100%;
|
|
89
|
+
-webkit-app-region: drag;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
header h1 {
|
|
93
|
+
margin-top: 0;
|
|
94
|
+
margin-bottom: 0;
|
|
95
|
+
font-size: 12px;
|
|
96
|
+
font-weight: bold;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
nav a {
|
|
100
|
+
margin-left: 10px;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#logo-block {
|
|
104
|
+
height: 40px;
|
|
105
|
+
max-width: 50%;
|
|
106
|
+
display: flex;
|
|
107
|
+
justify-content: space-between;
|
|
108
|
+
align-items: center;
|
|
109
|
+
gap: 8px;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#logo {
|
|
113
|
+
height: 100%;
|
|
114
|
+
width: 100%
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#drawer-block {
|
|
118
|
+
display: flex;
|
|
119
|
+
justify-content: space-between;
|
|
120
|
+
align-items: right;
|
|
121
|
+
gap: 8px;
|
|
122
|
+
padding-right: 30px;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
@media(prefers-color-scheme: light) {
|
|
126
|
+
header {
|
|
127
|
+
color: black;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
nav a {
|
|
131
|
+
color: initial;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
`
|
|
135
|
+
];
|
|
136
|
+
__decorate([
|
|
137
|
+
property()
|
|
138
|
+
], Header.prototype, "name", void 0);
|
|
139
|
+
__decorate([
|
|
140
|
+
property({ type: String })
|
|
141
|
+
], Header.prototype, "title", void 0);
|
|
142
|
+
__decorate([
|
|
143
|
+
property({ type: String })
|
|
144
|
+
], Header.prototype, "logo", void 0);
|
|
145
|
+
__decorate([
|
|
146
|
+
property({ type: Boolean })
|
|
147
|
+
], Header.prototype, "drawer", void 0);
|
|
148
|
+
export default Header;
|
|
149
|
+
// Define web component
|
|
150
|
+
customElements.define("hot-header", Header);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Index to import all components together
|
|
2
|
+
// import '@hotosm/ui/components';
|
|
3
|
+
export { default as Button } from './Button';
|
|
4
|
+
export { default as Header } from './Header';
|
|
5
|
+
export { default as Toolbar } from './Toolbar';
|
|
6
|
+
export { default as Tracking } from './Tracking';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hotosm/ui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.0a8",
|
|
4
4
|
"description": "Shared UI components with theming for use across HOTOSM tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,6 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@lit/react": "^1.0.4",
|
|
38
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
39
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
38
40
|
"@storybook/addon-essentials": "^7.6.5",
|
|
39
41
|
"@storybook/addon-links": "^7.6.5",
|
|
40
42
|
"@storybook/blocks": "^7.6.5",
|
|
@@ -42,6 +44,8 @@
|
|
|
42
44
|
"@storybook/web-components-vite": "^7.6.19",
|
|
43
45
|
"@typescript-eslint/eslint-plugin": "^6.4.0",
|
|
44
46
|
"@unocss/postcss": "^0.58.5",
|
|
47
|
+
"@web/rollup-plugin-html": "^2.3.0",
|
|
48
|
+
"@web/rollup-plugin-import-meta-assets": "^2.2.1",
|
|
45
49
|
"autoprefixer": "^10.4.16",
|
|
46
50
|
"class-variance-authority": "0.7.0",
|
|
47
51
|
"clsx": "2.0.0",
|
|
@@ -56,6 +60,10 @@
|
|
|
56
60
|
"lit": "^3.1.0",
|
|
57
61
|
"react": "^18.2.0",
|
|
58
62
|
"react-dom": "^18.2.0",
|
|
63
|
+
"rollup": "^4.18.0",
|
|
64
|
+
"rollup-plugin-css-only": "^4.5.2",
|
|
65
|
+
"rollup-plugin-minify-html-literals": "^1.2.6",
|
|
66
|
+
"rollup-plugin-summary": "^2.0.1",
|
|
59
67
|
"storybook": "^7.6.5",
|
|
60
68
|
"typescript": "^5.2.2",
|
|
61
69
|
"unocss": "^0.58.0",
|
|
@@ -66,6 +74,7 @@
|
|
|
66
74
|
"react-dom": "Required for Storybook"
|
|
67
75
|
},
|
|
68
76
|
"files": [
|
|
77
|
+
"dist/**/*",
|
|
69
78
|
"components/*.js",
|
|
70
79
|
"components/*.d.ts",
|
|
71
80
|
"react/*.js",
|
|
@@ -85,8 +94,10 @@
|
|
|
85
94
|
},
|
|
86
95
|
"homepage": "https://github.com/hotosm/ui#readme",
|
|
87
96
|
"scripts": {
|
|
88
|
-
"dev": "pnpm run
|
|
89
|
-
"
|
|
97
|
+
"dev": "pnpm run compile && storybook dev -p 3001 --no-open",
|
|
98
|
+
"compile": "tsc",
|
|
99
|
+
"copy-shoelace-assets": "rm -rf dist/assets/icons && cp -r node_modules/@shoelace-style/shoelace/dist/assets dist/",
|
|
100
|
+
"build": "pnpm run compile && rollup --config && pnpm run copy-shoelace-assets",
|
|
90
101
|
"build:docstrings": "wca analyze 'components/*.ts' --outDir 'docs/components' --format 'markdown'",
|
|
91
102
|
"build:stories": "pnpm run build && storybook build --output-dir=docs/stories",
|
|
92
103
|
"build:docs": "pnpm run build:docstrings && pnpm run build:stories",
|
package/react/Button.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { createComponent } from '@lit/react';
|
|
4
|
+
import Button from '../components/Button';
|
|
5
|
+
const reactWrapper = createComponent({
|
|
6
|
+
tagName: 'hot-button',
|
|
7
|
+
elementClass: Button,
|
|
8
|
+
react: React,
|
|
9
|
+
events: {
|
|
10
|
+
onClick: 'click',
|
|
11
|
+
},
|
|
12
|
+
displayName: 'hot-button'
|
|
13
|
+
});
|
|
14
|
+
export default reactWrapper;
|
package/react/Header.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { createComponent } from '@lit/react';
|
|
4
|
+
import Header from '../components/Header';
|
|
5
|
+
const reactWrapper = createComponent({
|
|
6
|
+
tagName: 'hot-header',
|
|
7
|
+
elementClass: Header,
|
|
8
|
+
react: React,
|
|
9
|
+
displayName: 'hot-header'
|
|
10
|
+
});
|
|
11
|
+
export default reactWrapper;
|
package/react/index.d.ts
ADDED
package/react/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Index to import all components together
|
|
2
|
+
// import '@hotosm/ui/react';
|
|
3
|
+
export { default as Button } from './Button';
|
|
4
|
+
export { default as Header } from './Header';
|
|
5
|
+
export { default as Toolbar } from './Toolbar';
|
|
6
|
+
export { default as Tracking } from './Tracking';
|
package/react/HotToolbar.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import Toolbar from '../components/Toolbar';
|
|
2
|
-
declare const reactWrapper: import("@lit/react").ReactWebComponent<Toolbar, {
|
|
3
|
-
onHotUndoClick: string;
|
|
4
|
-
onHotRedoClick: string;
|
|
5
|
-
onHotBoldClick: string;
|
|
6
|
-
onHotItalicClick: string;
|
|
7
|
-
onHotUnderlineClick: string;
|
|
8
|
-
onHotLeftalignClick: string;
|
|
9
|
-
onHotCenteralignClick: string;
|
|
10
|
-
onHotRightalignClick: string;
|
|
11
|
-
}>;
|
|
12
|
-
export default reactWrapper;
|
package/react/HotTracking.d.ts
DELETED
|
File without changes
|
|
File without changes
|