@rogieking/figui3 1.0.86 → 1.0.88

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 (3) hide show
  1. package/README.md +204 -40
  2. package/fig.js +22 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,89 +1,253 @@
1
- # Figma UI3 Web Components
1
+ # Fig.js
2
2
 
3
- figUI3 is a collection of custom web components that provide various UI elements and functionality for web applications. These components are designed to be easily integrated into your projects, offering a set of reusable and customizable UI elements.
3
+ A lightweight, customizable web component library that provides Figma-inspired UI elements for modern web applications.
4
4
 
5
- ## Table of Contents
5
+ ## Features
6
6
 
7
- - [Components](#components)
8
- - [Installation](#installation)
9
- - [Usage](#usage)
10
- - [Contributing](#contributing)
11
- - [License](#license)
7
+ - 🎨 Figma-inspired design system
8
+ - 📦 Zero dependencies
9
+ - 🚀 Lightweight and performant
10
+ - 🎯 Built with Web Components
11
+ - 🔧 Highly customizable
12
+ - 🌐 Framework agnostic
12
13
 
13
14
  ## Components
14
15
 
15
- The Fig Components library includes the following custom elements:
16
-
17
- 1. `<fig-button>`: A customizable button component.
18
- 2. `<fig-dropdown>`: A dropdown select component.
19
- 3. `<fig-tooltip>`: A tooltip component that can be triggered by hover or click.
20
- 4. `<fig-popover>`: A popover component similar to tooltip but with more flexibility.
21
- 5. `<fig-dialog>`: A dialog/modal component.
22
- 6. `<fig-tabs>`: A tabbed interface component.
23
- 7. `<fig-segmented-control>`: A segmented control component for mutually exclusive options.
24
- 8. `<fig-slider>`: A slider input component with optional text input.
25
- 9. `<fig-input-text>`: A text input component with optional append and prepend slots.
26
- 10. `<fig-field>`: A form field wrapper component.
27
- 11. `<fig-input-color>`: A color input component with optional text and alpha inputs.
28
- 12. `<fig-checkbox>`: A checkbox input component.
29
- 13. `<fig-switch>`: A switch/toggle input component.
16
+ The library includes the following components:
17
+
18
+ - `<fig-button>` - Versatile button component with multiple variants
19
+ - `<fig-slider>` - Input slider with optional text input and units
20
+ - `<fig-field>` - Form field wrapper with flexible layout options
21
+ - `<fig-dropdown>` - Customizable dropdown select
22
+ - `<fig-tooltip>` - Hover and click-triggered tooltips
23
+ - `<fig-dialog>` - Modal dialog component
24
+ - `<fig-input-color>` - Color picker with hex/rgba support
25
+ - And more...
30
26
 
31
27
  ## Installation
32
28
 
33
- To use Fig Components in your project, include the JavaScript file in your HTML:
29
+ ```bash
30
+ npm install fig-js
31
+ ```
32
+
33
+ Or include directly in your HTML:
34
34
 
35
35
  ```html
36
- <script src="path/to/fig-components.js"></script>
36
+ <script src="https://unpkg.com/fig-js@latest/dist/fig.js"></script>
37
37
  ```
38
38
 
39
- Make sure to replace `path/to/fig-components.js` with the actual path to the JavaScript file containing the component definitions.
40
-
41
39
  ## Usage
42
40
 
43
- After including the Fig Components script in your HTML, you can use the custom elements in your markup. Here are some examples:
41
+ ```html
42
+ <!-- Basic button -->
43
+ <fig-button>Click me</fig-button>
44
+
45
+ <!-- Slider with text input -->
46
+ <fig-field direction="horizontal">
47
+ <label>Opacity</label>
48
+ <fig-slider type="opacity" value="0.75" color="#ff0000" units="%" text="true">
49
+ </fig-slider>
50
+ </fig-field>
51
+ ```
52
+
53
+ ## Documentation
44
54
 
45
- ### Button
55
+ For detailed documentation and examples, visit our [documentation site](https://your-docs-site.com).
56
+
57
+ ## Browser Support
58
+
59
+ Fig.js supports all modern browsers that implement the Web Components standard:
60
+
61
+ - Chrome/Edge (Chromium) 67+
62
+ - Firefox 63+
63
+ - Safari 10.1+
64
+
65
+ ## Contributing
66
+
67
+ Contributions are welcome! Please read our [contributing guidelines](CONTRIBUTING.md) before submitting a pull request.
68
+
69
+ ## License
70
+
71
+ [MIT License](LICENSE)
72
+
73
+ ## Component Examples
74
+
75
+ ### Button (`<fig-button>`)
46
76
 
47
77
  ```html
78
+ <!-- Basic button -->
48
79
  <fig-button>Click me</fig-button>
80
+
81
+ <!-- Ghost variant with icon -->
82
+ <fig-button variant="ghost" icon="true">
83
+ <svg><!-- your icon svg --></svg>
84
+ </fig-button>
85
+
86
+ <!-- Disabled state -->
87
+ <fig-button disabled>Disabled</fig-button>
88
+
89
+ <!-- Toggle button -->
90
+ <fig-button type="toggle">Toggle Me</fig-button>
49
91
  ```
50
92
 
51
- ### Dropdown
93
+ ### Dropdown (`<fig-dropdown>`)
52
94
 
53
95
  ```html
96
+ <!-- Basic dropdown -->
54
97
  <fig-dropdown>
55
98
  <option value="1">Option 1</option>
56
99
  <option value="2">Option 2</option>
57
100
  <option value="3">Option 3</option>
58
101
  </fig-dropdown>
102
+
103
+ <!-- With default selection -->
104
+ <fig-dropdown value="2">
105
+ <option value="1">Option 1</option>
106
+ <option value="2">Option 2</option>
107
+ <option value="3">Option 3</option>
108
+ </fig-dropdown>
59
109
  ```
60
110
 
61
- ### Tooltip
111
+ ### Tooltip (`<fig-tooltip>`)
62
112
 
63
113
  ```html
114
+ <!-- Hover tooltip -->
64
115
  <fig-tooltip text="This is a tooltip" action="hover">
65
116
  Hover over me
66
117
  </fig-tooltip>
118
+
119
+ <!-- Click tooltip -->
120
+ <fig-tooltip text="Click tooltip" action="click"> Click me </fig-tooltip>
67
121
  ```
68
122
 
69
- ### Slider
123
+ ### Popover (`<fig-popover>`)
70
124
 
71
125
  ```html
72
- <fig-slider min="0" max="100" value="50" text></fig-slider>
126
+ <!-- Basic popover -->
127
+ <fig-popover>
128
+ <button slot="trigger">Open Popover</button>
129
+ <div slot="content">
130
+ <h3>Popover Title</h3>
131
+ <p>This is the popover content.</p>
132
+ </div>
133
+ </fig-popover>
73
134
  ```
74
135
 
75
- ### Color Input
136
+ ### Dialog (`<fig-dialog>`)
76
137
 
77
138
  ```html
78
- <fig-input-color value="#ff0000" text alpha></fig-input-color>
139
+ <!-- Basic dialog -->
140
+ <fig-dialog>
141
+ <h2 slot="header">Dialog Title</h2>
142
+ <div slot="content">
143
+ <p>Dialog content goes here.</p>
144
+ </div>
145
+ <div slot="footer">
146
+ <fig-button>Cancel</fig-button>
147
+ <fig-button variant="primary">Confirm</fig-button>
148
+ </div>
149
+ </fig-dialog>
79
150
  ```
80
151
 
81
- For more detailed usage instructions and examples for each component, please refer to the individual component documentation.
152
+ ### Tabs (`<fig-tabs>`)
82
153
 
83
- ## Contributing
154
+ ```html
155
+ <fig-tabs>
156
+ <fig-tab label="Tab 1">Content 1</fig-tab>
157
+ <fig-tab label="Tab 2">Content 2</fig-tab>
158
+ <fig-tab label="Tab 3">Content 3</fig-tab>
159
+ </fig-tabs>
160
+ ```
84
161
 
85
- Contributions to Fig Components are welcome! Please feel free to submit a Pull Request.
162
+ ### Segmented Control (`<fig-segmented-control>`)
86
163
 
87
- ## License
164
+ ```html
165
+ <fig-segmented-control>
166
+ <button value="1">Option 1</button>
167
+ <button value="2">Option 2</button>
168
+ <button value="3">Option 3</button>
169
+ </fig-segmented-control>
170
+ ```
88
171
 
89
- [MIT License](LICENSE)
172
+ ### Slider (`<fig-slider>`)
173
+
174
+ ```html
175
+ <!-- Basic slider -->
176
+ <fig-slider min="0" max="100" value="50"></fig-slider>
177
+
178
+ <!-- Slider with text input and units -->
179
+ <fig-slider min="0" max="100" value="75" text="true" units="%"> </fig-slider>
180
+
181
+ <!-- Opacity slider with color -->
182
+ <fig-slider type="opacity" value="0.75" color="#ff0000" units="%" text="true">
183
+ </fig-slider>
184
+ ```
185
+
186
+ ### Text Input (`<fig-input-text>`)
187
+
188
+ ```html
189
+ <!-- Basic text input -->
190
+ <fig-input-text value="Hello World"></fig-input-text>
191
+
192
+ <!-- With placeholder -->
193
+ <fig-input-text placeholder="Enter text..."></fig-input-text>
194
+
195
+ <!-- With prepend and append slots -->
196
+ <fig-input-text>
197
+ <span slot="prepend">$</span>
198
+ <span slot="append">.00</span>
199
+ </fig-input-text>
200
+ ```
201
+
202
+ ### Field (`<fig-field>`)
203
+
204
+ ```html
205
+ <!-- Vertical layout -->
206
+ <fig-field>
207
+ <label>Username</label>
208
+ <fig-input-text></fig-input-text>
209
+ <span class="help">Enter your username</span>
210
+ </fig-field>
211
+
212
+ <!-- Horizontal layout -->
213
+ <fig-field direction="horizontal">
214
+ <label>Volume</label>
215
+ <fig-slider min="0" max="100" value="50"></fig-slider>
216
+ </fig-field>
217
+ ```
218
+
219
+ ### Color Input (`<fig-input-color>`)
220
+
221
+ ```html
222
+ <!-- Basic color picker -->
223
+ <fig-input-color value="#ff0000"></fig-input-color>
224
+
225
+ <!-- With text input and alpha channel -->
226
+ <fig-input-color value="#ff0000" text="true" alpha="true"> </fig-input-color>
227
+ ```
228
+
229
+ ### Checkbox (`<fig-checkbox>`)
230
+
231
+ ```html
232
+ <!-- Basic checkbox -->
233
+ <fig-checkbox>Accept terms</fig-checkbox>
234
+
235
+ <!-- Checked state -->
236
+ <fig-checkbox checked>Selected option</fig-checkbox>
237
+
238
+ <!-- Indeterminate state -->
239
+ <fig-checkbox indeterminate>Parent option</fig-checkbox>
240
+ ```
241
+
242
+ ### Switch (`<fig-switch>`)
243
+
244
+ ```html
245
+ <!-- Basic switch -->
246
+ <fig-switch></fig-switch>
247
+
248
+ <!-- With label -->
249
+ <fig-switch>Enable notifications</fig-switch>
250
+
251
+ <!-- Checked state -->
252
+ <fig-switch checked>Active</fig-switch>
253
+ ```
package/fig.js CHANGED
@@ -100,6 +100,14 @@ if (window.customElements && !window.customElements.get("fig-dropdown")) {
100
100
  this.attachShadow({ mode: "open" });
101
101
  }
102
102
 
103
+ #addEventListeners() {
104
+ this.select.addEventListener("input", this.#handleSelectInput.bind(this));
105
+ this.select.addEventListener(
106
+ "change",
107
+ this.#handleSelectChange.bind(this)
108
+ );
109
+ }
110
+
103
111
  connectedCallback() {
104
112
  this.type = this.getAttribute("type") || "select";
105
113
 
@@ -111,17 +119,14 @@ if (window.customElements && !window.customElements.get("fig-dropdown")) {
111
119
  this.slotChange.bind(this)
112
120
  );
113
121
 
114
- this.select.addEventListener("input", this.#handleSelectInput.bind(this));
115
- this.select.addEventListener(
116
- "change",
117
- this.#handleSelectChange.bind(this)
118
- );
122
+ this.#addEventListeners();
119
123
  }
120
124
 
121
125
  slotChange() {
122
126
  while (this.select.firstChild) {
123
127
  this.select.firstChild.remove();
124
128
  }
129
+
125
130
  if (this.type === "dropdown") {
126
131
  const hiddenOption = document.createElement("option");
127
132
  hiddenOption.setAttribute("hidden", "true");
@@ -133,6 +138,7 @@ if (window.customElements && !window.customElements.get("fig-dropdown")) {
133
138
  this.select.appendChild(option.cloneNode(true));
134
139
  }
135
140
  });
141
+ this.#syncSelectedValue(this.value);
136
142
  if (this.type === "dropdown") {
137
143
  this.select.selectedIndex = -1;
138
144
  }
@@ -159,16 +165,23 @@ if (window.customElements && !window.customElements.get("fig-dropdown")) {
159
165
  }
160
166
  set value(value) {
161
167
  this.setAttribute("value", value);
162
- this.select.value = value;
163
- this.select.setAttribute("value", value);
164
168
  }
165
169
  static get observedAttributes() {
166
170
  return ["value", "type"];
167
171
  }
172
+ #syncSelectedValue(value) {
173
+ if (this.select) {
174
+ this.select.querySelectorAll("option").forEach((o, i) => {
175
+ if (o.value === this.getAttribute("value")) {
176
+ this.select.selectedIndex = i;
177
+ }
178
+ });
179
+ }
180
+ }
168
181
  attributeChangedCallback(name, oldValue, newValue) {
169
182
  if (name === "value") {
170
- this.select.value = newValue;
171
- this.select.setAttribute("value", newValue);
183
+ this.#syncSelectedValue(newValue);
184
+ console.log("val:", this.value);
172
185
  }
173
186
  if (name === "type") {
174
187
  this.type = newValue;
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.86"
3
+ "version": "1.0.88"
4
4
  }