Web Components Integration
Inglorious Web works seamlessly with Web Component libraries and design systems.
Why Integrate Web Components?
Web Components are useful for:
- Complex UI — Date pickers, rich editors, advanced data viz
- Third-party Libraries — Shoelace, Material Web Components, Lion
- Specialized Functionality — Things Inglorious doesn't provide
- Cross-framework Sharing — Components work anywhere
Using Web Components
Basic Example: Shoelace Color Picker
bash
npm install @shoelace-style/shoelace
1
javascript
import "@shoelace-style/shoelace/dist/components/color-picker/color-picker.js"
const themeEditor = {
colorChange(entity, color) {
entity.primaryColor = color
},
render(entity, api) {
return html`
<div>
<label>Primary Color</label>
<sl-color-picker
value=${entity.primaryColor}
@sl-change=${(e) =>
api.notify("#themeEditor:colorChange", e.target.value)}
></sl-color-picker>
</div>
`
},
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
With Attributes
javascript
render(entity, api) {
return html`
<sl-select
label="Choose an option"
?disabled=${entity.isDisabled}
@sl-change=${(e) => api.notify('#select:changed', e.target.value)}
>
${entity.options.map(opt => html`
<sl-option value=${opt.id}>${opt.name}</sl-option>
`)}
</sl-select>
`
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
Hybrid Approach
Use Inglorious Web components for core patterns, Web Components for specialized UI:
javascript
import { form } from "@inglorious/web/form"
import { table } from "@inglorious/web/table"
import "@shoelace-style/shoelace/dist/components/date-picker/date-picker.js"
const types = {
// Inglorious form for business logic
form: {
...form,
render(entity, api) {
return html`
<form>
<!-- Inglorious form fields -->
${api.render("emailField")}
<!-- Web Component for date pick -->
<label>Birth Date</label>
<sl-date-picker
@sl-change=${(e) =>
api.notify("#form:fieldChange", {
path: "birthDate",
value: e.target.value,
})}
></sl-date-picker>
</form>
`
},
},
// Inglorious table for data display
dataTable: {
...table,
// Customize as needed
},
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
SSR/SSG Limitations
⚠️ Important for @inglorious/ssx projects:
Most Web Component libraries (Shoelace, Material Web Components) require JavaScript to initialize and don't pre-render to HTML. This means:
- Won't appear in pre-rendered HTML
- Not SEO-friendly in initial state
- May cause FOUC (Flash of Unstyled Content)
- Should be client-only enhancements
Recommendation: Use Inglorious Web components for SSX/SSG projects.
Popular Libraries
Shoelace
Rich, accessible component library. Great for design systems.
bash
npm install @shoelace-style/shoelace
1
Material Web Components
Google's Material Design components.
bash
npm install @material/web
1
Lion
Open-source, accessible Web Components.
bash
npm install @lion/button @lion/form
1
Best Practices
✅ Do:
- Use Inglorious for core business logic
- Use Web Components for specialized UI
- Integrate through events (api.notify)
- Keep store state primary (not component internal state)
- Test Web Component integration through store events
❌ Don't:
- Store state inside Web Components
- Bypass Inglorious event system
- Rely on Web Components for critical business logic
- Use Web Components for simple patterns (buttons, inputs, etc.)
Debugging
If Web Components aren't updating correctly:
- Check event handling — Make sure you're dispatching the right events
- Property vs Attribute — Use
.propertyfor properties, not attributes - Timing — Web Component may initialize after first render
- Ref binding — Use
ref()directive if you need direct access
javascript
import { ref } from "lit-html"
const picker = {
render(entity, api) {
const colorRef = ref()
return html`
<sl-color-picker
${colorRef}
@sl-change=${(e) => {
// Direct access via ref if needed
console.log(colorRef.value.value)
}}
></sl-color-picker>
`
},
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Related
- Components Overview — Inglorious Web's built-in components
- Advanced — Type composition and other patterns
Happy integrating! 🎉
Inglorious Web