@phun-ky/speccer 11.2.27 → 11.2.29

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
@@ -34,6 +34,9 @@ webpage. If you need to draw attention to elements, **SPECCER** is your tool!
34
34
  - [Script](#script)
35
35
  - [Advanced usage](#advanced-usage)
36
36
  - [React](#react)
37
+ - [1. Create a hook](#1-create-a-hook)
38
+ - [2. Use the hook](#2-use-the-hook)
39
+ - [Storybook](#storybook)
37
40
  - [Features](#features)
38
41
  - [Element spacing](#element-spacing)
39
42
  - [Bound spacing](#bound-spacing)
@@ -41,6 +44,7 @@ webpage. If you need to draw attention to elements, **SPECCER** is your tool!
41
44
  - [Slim measure](#slim-measure)
42
45
  - [Pin element to annotate or highlight the anatomy](#pin-element-to-annotate-or-highlight-the-anatomy)
43
46
  - [Default](#default)
47
+ - [Bracket](#bracket)
44
48
  - [Enclose](#enclose)
45
49
  - [Align with parent container](#align-with-parent-container)
46
50
  - [Pin with text](#pin-with-text)
@@ -189,7 +193,6 @@ If you use React, you can use an effect like this:
189
193
 
190
194
  ```javascript
191
195
  import React, { useEffect } from 'react';
192
- import PropTypes from 'prop-types';
193
196
 
194
197
  import debounce from './lib/debounce';
195
198
  import '@phun-ky/speccer/dist/speccer.min.css';
@@ -218,6 +221,94 @@ const Component = () => {
218
221
  export default Component;
219
222
  ```
220
223
 
224
+ Or a hook like this:
225
+
226
+ #### 1. Create a hook
227
+
228
+ ```typescript
229
+ // ./hooks/useSpeccer.ts
230
+ import { useEffect } from 'react';
231
+ import '@phun-ky/speccer/dist/speccer.min.css';
232
+ import debounce from './lib/debounce';
233
+
234
+ const useSpeccer = () => {
235
+ useEffect(() => {
236
+ let speccerEventFunc: () => void;
237
+
238
+ const loadSpeccer = async () => {
239
+ const { default: speccer } = await import('@phun-ky/speccer');
240
+ speccer();
241
+
242
+ speccerEventFunc = debounce(() => {
243
+ speccer();
244
+ }, 300);
245
+
246
+ window.addEventListener('resize', speccerEventFunc);
247
+ };
248
+
249
+ loadSpeccer();
250
+
251
+ return () => {
252
+ if (speccerEventFunc) {
253
+ window.removeEventListener('resize', speccerEventFunc);
254
+ }
255
+ };
256
+ }, []);
257
+ };
258
+ ```
259
+
260
+ #### 2. Use the hook
261
+
262
+ ```typescript
263
+ import { useSpeccer } from './hooks/useSpeccer';
264
+
265
+ export const MyComponent = () => {
266
+
267
+ useSpeccer();
268
+
269
+ return <div data-speccer="pin bracket top">…</div>;
270
+ };
271
+ ```
272
+
273
+ ### Storybook
274
+
275
+ With the same approach mentioned above, you can add **SPECCER** to your stories!
276
+
277
+ ![Image of the Storybook implementation](./public/storybook.png)
278
+
279
+ ```typescript
280
+ import "@phun-ky/speccer/dist/speccer.min.css";
281
+ import { ComponentMeta, ComponentStory } from "@storybook/react";
282
+ import { MyComponent } from '../path-to-component/MyComponent';
283
+
284
+ export default {
285
+ title: 'Components/MyComponent',
286
+ component: MyComponent,
287
+ tags: ['autodocs'],
288
+
289
+
290
+ } as ComponentMeta<typeof MyComponent>
291
+
292
+ const Template: ComponentStory<typeof MyComponent> = (args) => {
293
+ useSpeccer();
294
+
295
+ return (
296
+ <div data-speccer="pin-area">
297
+ <MyComponent {...args} />
298
+ </div>
299
+ );
300
+ };
301
+
302
+ export const Basic = Template.bind({});
303
+ Basic.args = {
304
+ …,
305
+ "data-speccer": "pin bracket top",
306
+ };
307
+ ```
308
+
309
+ > [!IMPORTANT] Just make sure `MyComponent` passed down the attributes to the
310
+ > DOM element
311
+
221
312
  ## Features
222
313
 
223
314
  ### Element spacing
@@ -315,6 +406,14 @@ This will place a pin to the outline of the element. Default is `top`.
315
406
  </div>
316
407
  ```
317
408
 
409
+ #### Bracket
410
+
411
+ ```html
412
+ <div data-speccer="pin-area">
413
+ <div data-speccer="pin bracket" class="…"></div>
414
+ </div>
415
+ ```
416
+
318
417
  #### Enclose
319
418
 
320
419
  ![Image of speccer](./public/speccer-pin-enclose-light.png)
@@ -2,7 +2,7 @@
2
2
  * @phun-ky/speccer
3
3
  * A script to annotate, show spacing specs and to display typography information in documentation/website on HTML elements
4
4
  * @author Alexander Vassbotn Røyne-Helgesen <alexander@phun-ky.net>
5
- * @version 11.2.27
5
+ * @version 11.2.29
6
6
  * @license
7
7
  * Copyright (c) 2018-2025 Alexander Vassbotn Røyne-Helgesen
8
8
  *
package/dist/speccer.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * @phun-ky/speccer
3
3
  * A script to annotate, show spacing specs and to display typography information in documentation/website on HTML elements
4
4
  * @author Alexander Vassbotn Røyne-Helgesen <alexander@phun-ky.net>
5
- * @version 11.2.27
5
+ * @version 11.2.29
6
6
  * @license
7
7
  * Copyright (c) 2018-2025 Alexander Vassbotn Røyne-Helgesen
8
8
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phun-ky/speccer",
3
- "version": "11.2.27",
3
+ "version": "11.2.29",
4
4
  "description": "A script to annotate, show spacing specs and to display typography information in documentation/website on HTML elements",
5
5
  "keywords": [
6
6
  "a11y",
@@ -29,7 +29,11 @@
29
29
  "specifications",
30
30
  "specs",
31
31
  "typescript",
32
- "typography"
32
+ "typography",
33
+ "storybook",
34
+ "stories",
35
+ "react",
36
+ "hooks"
33
37
  ],
34
38
  "homepage": "https://phun-ky.net/projects/speccer",
35
39
  "bugs": {
@@ -88,7 +92,7 @@
88
92
  "@rollup/plugin-terser": "^0.4.4",
89
93
  "@testing-library/dom": "^10.4.0",
90
94
  "@testing-library/jest-dom": "^6.4.2",
91
- "@types/node": "^22.13.1",
95
+ "@types/node": "^24.0.3",
92
96
  "cobertura": "^1.0.1",
93
97
  "cssnano": "^7.0.6",
94
98
  "eslint": "^9.20.0",