@hotosm/ui 0.2.0-a8 → 0.2.0-b0

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 CHANGED
@@ -47,95 +47,54 @@ currently written in **Lit**, using TypeScript.
47
47
 
48
48
  ## Install
49
49
 
50
- Via NPM:
50
+ There are two options for install:
51
51
 
52
- ```bash
53
- npm install @hotosm/ui
52
+ - **NPM**: appropriate for applications that have installable dependencies.
53
+ - **CDN**: appropriate for HTML / Markdown / HTMX.
54
54
 
55
- yarn add @hotosm/ui
55
+ ### Components Bundle
56
56
 
57
- pnpm install @hotosm/ui
58
- ```
57
+ - This is the compiled JavaScript bundle generated from the TypeScript code.
58
+ - The components require no additional dependencies and are minified.
59
59
 
60
- ## Usage
60
+ #### Via NPM
61
61
 
62
- ### CDN (HTML / HTMX)
62
+ - Install package `@hotosm/ui` as a dependency in your `package.json`.
63
+ - Import the components.
63
64
 
64
65
  ```html
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" />
70
- <script
71
- type="module"
72
- src="https://cdn.jsdelivr.net/npm/@shoelace-style/
73
- shoelace@2.15.1/cdn/shoelace-autoloader.js"
74
- ></script>
75
-
76
- // Import the components & styles (or add your own styling)
77
- <link
78
- rel="stylesheet"
79
- href="https://s3.amazonaws.com/hotosm-ui/latest/theme/styles.css"
80
- />
81
- <script
82
- type="module"
83
- src="https://s3.amazonaws.com/hotosm-ui/latest/components/Button.js"
84
- ></script>
85
-
86
- <div>
87
- <hot-button disabled> </hot-button>
88
- </div>
89
- ```
90
-
91
- > Using the Shoelace autoloader will lazy load only the components you use.
92
-
93
- See the docs for more [usage examples](https://hotosm.github.io/ui/usage/).
94
-
95
- > Components are versioned under subdirectories, with /latest/ tracking the
96
- > `main` branch, plus versioned releases.
97
-
98
- ### ES6 Imports (most frameworks)
99
-
100
- Install your required version with a pin, or latest:
101
-
102
- ```bash
103
- pnpm install @hotosm/ui
104
- ```
105
-
106
- ```js
107
66
  <script>
108
- import '@hotosm/ui/theme/styles.css'
109
- import '@hotosm/ui/components/Button'
67
+ import '@hotosm/ui/dist/components.js';
110
68
  </script>
111
69
 
112
- <hot-button disabled></hot-button>
70
+ // Use the components in your templates
71
+ <hot-button disabled> </hot-button>
113
72
  ```
114
73
 
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:
74
+ #### Via CDN
126
75
 
127
76
  ```html
128
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@shoelace-style
129
- /shoelace@2.15.1/cdn/themes/light.css" />
77
+ <script
78
+ type="module"
79
+ src="https://cdn.jsdelivr.net/npm/@hotosm/ui@latest/dist/components.js"
80
+ ></script>
130
81
 
131
- // Or dark
132
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@shoelace-style
133
- /shoelace@2.15.1/cdn/themes/dark.css" />
82
+ <hot-button disabled> </hot-button>
134
83
  ```
135
84
 
136
- ##### 2. Bundle Assets Yourself
85
+ The `jsdelivr` CDN only includes package releases, with `@latest` pointing to the
86
+ most recent tagged release.
87
+
88
+ There is also an S3-based CDN, where `latest` tracks the `main` branch of the repo:
89
+ `https://s3.amazonaws.com/hotosm-ui/latest/dist/components.js`
90
+
91
+ ### ES Modules
137
92
 
138
- - Add Shoelace as a `peerDependency` and to your `package.json`:
93
+ - Using the TypeScript ES Modules allows for cherry-picking components, so
94
+ 'tree-shaking' can remove the remaining ones you don't use.
95
+ - If you are developing an application that uses `@hotosm/ui` components,
96
+ including a bundler such as rollup/vite/webpack, this is probably the best approach.
97
+ - However, you must first add Shoelace as a `peerDependency` in your `package.json`:
139
98
 
140
99
  ```json
141
100
  "peerDependencies": {
@@ -143,29 +102,23 @@ Just add the Shoelace icons via CDN in your HTML file:
143
102
  }
144
103
  ```
145
104
 
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
- ```
105
+ > Ideally the version of Shoelace installed should match the version used in
106
+ > hotosm/ui.
165
107
 
166
- - Now the Shoelace assets will be bundled with your dist, under `/shoelace`.
108
+ - This will also install subdependencies such as Lit.
109
+ - If there is a conflict between Lit versions, the `lit` package can also be pinned
110
+ via `peerDependency`.
167
111
 
168
- #### React
112
+ Example:
113
+
114
+ ```js
115
+ import '@hotosm/ui/components/Toolbar';
116
+
117
+ // Then in your template
118
+ <hot-button>Click Me</hot-button>
119
+ ```
120
+
121
+ ### React
169
122
 
170
123
  Versions of React below v19 require a specific 'wrapper' component to use the
171
124
  web components.
@@ -194,13 +147,16 @@ const HomePage = ({}) => {
194
147
  export default HomePage;
195
148
  ```
196
149
 
150
+ > Note that while web components must always have a closing tag, this is not
151
+ > required for the React wrappers.
152
+
197
153
  ## Using Extra Shoelace Components
198
154
 
199
155
  The UI library is not comprehensive & you may wish to use additional components
200
156
  from Shoelace in your app.
201
157
 
202
158
  Ideally you should install the same version of @shoelace-style/shoelace as this
203
- library.
159
+ library (particularly if using the ES Modules)
204
160
 
205
161
  To determine which version:
206
162
 
@@ -212,4 +168,20 @@ To determine which version:
212
168
  - The version of shoelace used should be in the `dependencies` section.
213
169
 
214
170
  If you are using a bundler, you must bundle the (icon) assets yourself,
215
- as described above.
171
+ described in the Shoelace docs.
172
+
173
+ ### Example of bundling assets
174
+
175
+ - To include the Shoelace assets in your final bundle (dist), you could add
176
+ the following to your `package.json`:
177
+
178
+ ```json
179
+ "scripts": {
180
+ "clean-icons": "rm -rf public/assets/icons",
181
+ "get-icons": "cp -r node_modules/@shoelace-style/shoelace/dist/assets/icons public/",
182
+ "setup-dist": "pnpm run clean-icons && pnpm run get-icons",
183
+ }
184
+ ```
185
+
186
+ - Now the Shoelace assets will be bundled with your dist, under `/shoelace`.
187
+ - Following the example, also add `public/assets/icons` to your `.gitignore` file.
@@ -12,6 +12,8 @@ import '@shoelace-style/shoelace/dist/components/tab-panel/tab-panel.js';
12
12
  import '@shoelace-style/shoelace/dist/components/tab/tab.js';
13
13
  import { LitElement, css, html } from "lit";
14
14
  import { property } from "lit/decorators.js";
15
+ import registerBundledIcons from '../theme/icons/bundled';
16
+ registerBundledIcons();
15
17
  const hotLogo = new URL('../theme/logo.png', import.meta.url);
16
18
  // import { cva } from "class-variance-authority";
17
19
  // const headerStyle = cva(
@@ -58,7 +60,7 @@ export class Header extends LitElement {
58
60
 
59
61
  ${this.drawer ? html `
60
62
  <div id="drawer-block" style="font-size: 32px;">
61
- <sl-icon-button name="list" label="drawer-open"></sl-icon-button>
63
+ <sl-icon-button library="bundled" name="list" label="drawer-open"></sl-icon-button>
62
64
  </div>
63
65
  ` : null}
64
66
 
@@ -13,6 +13,8 @@ import '@shoelace-style/shoelace/dist/components/icon/icon.js';
13
13
  import '@shoelace-style/shoelace/dist/components/tooltip/tooltip.js';
14
14
  import { LitElement, css, html } from "lit";
15
15
  import { property } from "lit/decorators.js";
16
+ import registerBundledIcons from '../theme/icons/bundled';
17
+ registerBundledIcons();
16
18
  // import { cva } from "class-variance-authority";
17
19
  // const toolbarStyle = cva(
18
20
  // "some-css-var",
@@ -99,7 +101,7 @@ export class Toolbar extends LitElement {
99
101
  renderButton({ content, icon, label, action }) {
100
102
  return html `
101
103
  <sl-tooltip content=${content} placement="${this.tooltipPosition}">
102
- <sl-button @click=${action ?? (() => { })}><sl-icon name=${icon} label=${label}></sl-icon></sl-button>
104
+ <sl-button @click=${action ?? (() => { })}><sl-icon library="bundled" name=${icon} label=${label}></sl-icon></sl-button>
103
105
  </sl-tooltip>
104
106
  `;
105
107
  }
@@ -10,6 +10,8 @@ import '@shoelace-style/shoelace/dist/themes/dark.css';
10
10
  import '@shoelace-style/shoelace/dist/components/alert/alert.js';
11
11
  import { LitElement, css, html } from "lit";
12
12
  import { property, state } from "lit/decorators.js";
13
+ import registerBundledIcons from '../theme/icons/bundled';
14
+ registerBundledIcons();
13
15
  export class Tracking extends LitElement {
14
16
  constructor() {
15
17
  super(...arguments);
@@ -25,7 +27,7 @@ export class Tracking extends LitElement {
25
27
  variant="danger"
26
28
  ?open=${this.isOpen}
27
29
  >
28
- <sl-icon id="hot-red-text" slot="icon" name="info-circle"></sl-icon>
30
+ <sl-icon id="hot-red-text" library="bundled" slot="icon" name="info-circle"></sl-icon>
29
31
 
30
32
  <p id="tracking-header">
31
33
  About the information we collect
Binary file