@richpods/coloeus 0.1.0 → 0.1.2

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.
Files changed (2) hide show
  1. package/README.md +190 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # @richpods/coloeus
2
+
3
+ Embeddable Vue 3 poll components for the Coloeus poll service.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @richpods/coloeus
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```ts
14
+ import { createApp } from 'vue'
15
+ import { configureColoeus, ColoeusPolls } from '@richpods/coloeus'
16
+ import '@richpods/coloeus/style.css'
17
+
18
+ // Configure the API endpoint
19
+ configureColoeus({
20
+ apiUrl: 'https://your-api.example.com'
21
+ })
22
+
23
+ const app = createApp(App)
24
+ app.component('ColoeusPolls', ColoeusPolls)
25
+ app.mount('#app')
26
+ ```
27
+
28
+ ## Configuration
29
+
30
+ Before using any components, configure the library with your API endpoint:
31
+
32
+ ```ts
33
+ import { configureColoeus } from '@richpods/coloeus'
34
+
35
+ configureColoeus({
36
+ apiUrl: 'https://your-api.example.com',
37
+ // Optional: provide auth token for admin operations
38
+ getAuthToken: async () => {
39
+ return await yourAuthService.getToken()
40
+ }
41
+ })
42
+ ```
43
+
44
+ ### Config Options
45
+
46
+ | Option | Type | Required | Description |
47
+ |--------|------|----------|-------------|
48
+ | `apiUrl` | `string` | Yes | Base URL of your Coloeus API |
49
+ | `getAuthToken` | `() => Promise<string \| null>` | No | Async function returning a JWT for authenticated requests |
50
+
51
+ ## Components
52
+
53
+ ### ColoeusPolls
54
+
55
+ Displays a poll and allows users to vote.
56
+
57
+ ```vue
58
+ <template>
59
+ <ColoeusPolls
60
+ id="your-poll-id"
61
+ @voted="handleVoted"
62
+ @error="handleError"
63
+ />
64
+ </template>
65
+
66
+ <script setup>
67
+ import { ColoeusPolls } from '@richpods/coloeus'
68
+
69
+ function handleVoted(pollId, optionIndices) {
70
+ console.log(`Voted on poll ${pollId}:`, optionIndices)
71
+ }
72
+
73
+ function handleError(error) {
74
+ console.error('Vote error:', error)
75
+ }
76
+ </script>
77
+ ```
78
+
79
+ #### Props
80
+
81
+ | Prop | Type | Required | Description |
82
+ |------|------|----------|-------------|
83
+ | `id` | `string` | Yes | The poll ID to display |
84
+
85
+ #### Events
86
+
87
+ | Event | Payload | Description |
88
+ |-------|---------|-------------|
89
+ | `voted` | `(pollId: string, optionIndices: number[])` | Emitted after a successful vote |
90
+ | `error` | `(error: string)` | Emitted when an error occurs |
91
+
92
+ ### ColoeusEditor
93
+
94
+ Create or edit polls. Requires authentication via `getAuthToken`.
95
+
96
+ ```vue
97
+ <template>
98
+ <ColoeusEditor
99
+ :id="pollId"
100
+ @saved="handleSaved"
101
+ @cancel="handleCancel"
102
+ @error="handleError"
103
+ />
104
+ </template>
105
+
106
+ <script setup>
107
+ import { ColoeusEditor } from '@richpods/coloeus'
108
+
109
+ const pollId = undefined // omit for create mode, provide ID for edit mode
110
+
111
+ function handleSaved(poll) {
112
+ console.log('Poll saved:', poll)
113
+ }
114
+
115
+ function handleCancel() {
116
+ console.log('Edit cancelled')
117
+ }
118
+
119
+ function handleError(error) {
120
+ console.error('Save error:', error)
121
+ }
122
+ </script>
123
+ ```
124
+
125
+ #### Props
126
+
127
+ | Prop | Type | Required | Description |
128
+ |------|------|----------|-------------|
129
+ | `id` | `string` | No | Poll ID to edit. Omit to create a new poll |
130
+
131
+ #### Events
132
+
133
+ | Event | Payload | Description |
134
+ |-------|---------|-------------|
135
+ | `saved` | `(poll: AdminPoll)` | Emitted after successful save |
136
+ | `cancel` | none | Emitted when cancel is clicked |
137
+ | `error` | `(error: string)` | Emitted when an error occurs |
138
+
139
+ ## Composables
140
+
141
+ For advanced use cases, you can use the composables directly:
142
+
143
+ ```ts
144
+ import { usePoll, useVote } from '@richpods/coloeus'
145
+
146
+ // Fetch and manage poll state
147
+ const { poll, loading, error, totalVotes, isActive } = usePoll('poll-id')
148
+
149
+ // Manage voting state
150
+ const { selectedOptions, submitVote, alreadyVoted } = useVote('poll-id')
151
+ ```
152
+
153
+ ## Types
154
+
155
+ TypeScript types are included:
156
+
157
+ ```ts
158
+ import type {
159
+ PublicPoll,
160
+ PollOption,
161
+ VoteResponse,
162
+ CreatePollInput,
163
+ UpdatePollInput,
164
+ AdminPoll,
165
+ ColoeusConfig
166
+ } from '@richpods/coloeus'
167
+ ```
168
+
169
+ ## Styling
170
+
171
+ Import the default styles:
172
+
173
+ ```ts
174
+ import '@richpods/coloeus/style.css'
175
+ ```
176
+
177
+ All components use BEM-style class names prefixed with `coloeus-` for easy customization:
178
+
179
+ - `.coloeus-poll` - Poll container
180
+ - `.coloeus-poll__title` - Poll title
181
+ - `.coloeus-poll__options` - Options list
182
+ - `.coloeus-poll__option` - Individual option
183
+ - `.coloeus-poll__vote-btn` - Vote button
184
+ - `.coloeus-editor` - Editor container
185
+ - `.coloeus-editor__field` - Form field
186
+ - `.coloeus-editor__input` - Input element
187
+
188
+ ## License
189
+
190
+ [Blue Oak Model License 1.0.0](https://blueoakcouncil.org/license/1.0.0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@richpods/coloeus",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Coloeus Poll Components - Embeddable Vue 3 components",
5
5
  "license": "BlueOak-1.0.0",
6
6
  "author": "Philipp Naderer-Puiu",
@@ -19,7 +19,7 @@
19
19
  "import": "./dist/coloeus-components.js",
20
20
  "require": "./dist/coloeus-components.umd.cjs"
21
21
  },
22
- "./style.css": "./dist/style.css"
22
+ "./style.css": "./dist/coloeus-components.css"
23
23
  },
24
24
  "files": ["dist", "LICENSE"],
25
25
  "scripts": {