@cal.macconnachie/web-components 0.0.1
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 +164 -0
- package/dist/components/cals-auth +2479 -0
- package/dist/components/index.d.ts +111 -0
- package/dist/index +2437 -0
- package/dist/index.d.ts +111 -0
- package/dist/stylesheets/main.css +1 -0
- package/package.json +73 -0
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Cals Web Components
|
|
2
|
+
|
|
3
|
+
Repo to handle any and all web components I may want to build
|
|
4
|
+
|
|
5
|
+
## Install & use
|
|
6
|
+
|
|
7
|
+
### Option 1: Load the full bundle (all components)
|
|
8
|
+
|
|
9
|
+
Load all components from the CDN:
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<script type="module" src="https://cdn.cals-api.com/index"></script>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Option 2: Load individual components (recommended)
|
|
16
|
+
|
|
17
|
+
Load only the components you need:
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<!-- Load just the auth component -->
|
|
21
|
+
<script type="module" src="https://cdn.cals-api.com/components/cals-auth"></script>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Option 3: Using with Vue, React, or other frameworks
|
|
25
|
+
|
|
26
|
+
For framework projects (Vue, React, etc.), load the component via script tag in your `index.html`:
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<!-- index.html -->
|
|
30
|
+
<script type="module" src="https://cdn.cals-api.com/components/cals-auth"></script>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Then create a type declaration file for TypeScript support:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
// src/types/cals-auth.d.ts
|
|
37
|
+
export interface CalsAuth extends HTMLElement {
|
|
38
|
+
openModal(): void;
|
|
39
|
+
logout(): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
declare global {
|
|
43
|
+
interface HTMLElementTagNameMap {
|
|
44
|
+
'cals-auth': CalsAuth;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Now you can use it with full type safety in your components:
|
|
50
|
+
|
|
51
|
+
**Vue:**
|
|
52
|
+
```vue
|
|
53
|
+
<template>
|
|
54
|
+
<cals-auth ref="authRef" app-name="Marketplace"></cals-auth>
|
|
55
|
+
<button @click="openAuth">Login / Sign up</button>
|
|
56
|
+
</template>
|
|
57
|
+
|
|
58
|
+
<script setup lang="ts">
|
|
59
|
+
import { ref } from 'vue';
|
|
60
|
+
import type { CalsAuth } from '@/types/cals-auth';
|
|
61
|
+
|
|
62
|
+
const authRef = ref<CalsAuth>();
|
|
63
|
+
|
|
64
|
+
const openAuth = () => {
|
|
65
|
+
authRef.value?.openModal();
|
|
66
|
+
};
|
|
67
|
+
</script>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**React:**
|
|
71
|
+
```tsx
|
|
72
|
+
import { useRef } from 'react';
|
|
73
|
+
import type { CalsAuth } from '@/types/cals-auth';
|
|
74
|
+
|
|
75
|
+
function App() {
|
|
76
|
+
const authRef = useRef<CalsAuth>(null);
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<>
|
|
80
|
+
<cals-auth ref={authRef} app-name="Marketplace"></cals-auth>
|
|
81
|
+
<button onClick={() => authRef.current?.openModal()}>
|
|
82
|
+
Login / Sign up
|
|
83
|
+
</button>
|
|
84
|
+
</>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Usage Example
|
|
90
|
+
|
|
91
|
+
HTML:
|
|
92
|
+
|
|
93
|
+
```html
|
|
94
|
+
<cals-auth id="cals-auth" app-name="Marketplace"></cals-auth>
|
|
95
|
+
|
|
96
|
+
<button id="open-auth">Login / Sign up</button>
|
|
97
|
+
<button id="logout-auth">Logout</button>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
JavaScript:
|
|
101
|
+
```js
|
|
102
|
+
const auth = document.querySelector('cals-auth');
|
|
103
|
+
|
|
104
|
+
document.getElementById('open-auth')?.addEventListener('click', () => {
|
|
105
|
+
auth?.openModal();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
document.getElementById('logout-auth')?.addEventListener('click', () => {
|
|
109
|
+
auth?.logout();
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
TypeScript:
|
|
114
|
+
```typescript
|
|
115
|
+
import type { CalsAuth } from 'https://cdn.cals-api.com/components/cals-auth';
|
|
116
|
+
|
|
117
|
+
const auth = document.querySelector<CalsAuth>('cals-auth');
|
|
118
|
+
|
|
119
|
+
document.getElementById('open-auth')?.addEventListener('click', () => {
|
|
120
|
+
auth?.openModal();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
document.getElementById('logout-auth')?.addEventListener('click', () => {
|
|
124
|
+
auth?.logout();
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Available Components
|
|
129
|
+
|
|
130
|
+
- `cals-auth` - Authentication component with sign in, sign up, and password reset
|
|
131
|
+
|
|
132
|
+
## Project Structure
|
|
133
|
+
|
|
134
|
+
This repository uses Yarn workspaces to manage two packages:
|
|
135
|
+
- **Root package** (`web-components`): The Lit web component library
|
|
136
|
+
- **CDN package** (`cdn/`): AWS CDK infrastructure for deploying the component to CloudFront
|
|
137
|
+
|
|
138
|
+
## Develop
|
|
139
|
+
|
|
140
|
+
### Web Component Development
|
|
141
|
+
- `yarn install` – install dependencies for all workspaces
|
|
142
|
+
- `yarn dev` – run the Vite playground at `http://localhost:5173`
|
|
143
|
+
- `yarn build` – bundle the full library to `dist/`
|
|
144
|
+
- `yarn build:components` – build individual components to `dist/components/{component-name}/`
|
|
145
|
+
- `yarn typecheck` – run TypeScript without emitting
|
|
146
|
+
|
|
147
|
+
### CDK Infrastructure
|
|
148
|
+
- `yarn cdk:synth` – synthesize the CDK stack
|
|
149
|
+
- `yarn cdk:diff` – compare deployed stack with current state
|
|
150
|
+
- `yarn cdk:deploy` – deploy the CDK stack to AWS
|
|
151
|
+
- `yarn cdk:destroy` – destroy the CDK stack
|
|
152
|
+
- `yarn cdk <command>` – run any CDK command
|
|
153
|
+
|
|
154
|
+
## Publish
|
|
155
|
+
|
|
156
|
+
Publishing to the CDN is automated on pushes to `main` via `.github/workflows/publish.yml`.
|
|
157
|
+
|
|
158
|
+
The workflow:
|
|
159
|
+
1. Builds the full bundle and individual components
|
|
160
|
+
2. Deploys the CDK stack (S3 + CloudFront)
|
|
161
|
+
3. Uploads files to S3:
|
|
162
|
+
- Full bundle at root: `https://cdn.cals-api.com/index.es.js`
|
|
163
|
+
- Individual components: `https://cdn.cals-api.com/components/{component-name}/index.es.js`
|
|
164
|
+
4. Invalidates CloudFront cache
|