@amedia/brick-mcp 1.0.3 → 1.0.5

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.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: brick-helloworld
3
- version: 2.0.2
3
+ version: 2.1.0
4
4
  selector: brick-helloworld-v2
5
5
  category: Development
6
6
  tags:
@@ -12,6 +12,8 @@ tags:
12
12
  web-components,
13
13
  template,
14
14
  getting-started,
15
+ i18n,
16
+ localisation,
15
17
  ]
16
18
  use_cases:
17
19
  [
@@ -20,209 +22,176 @@ use_cases:
20
22
  understanding-component-anatomy,
21
23
  server-side-rendering-examples,
22
24
  client-side-rendering-examples,
25
+ localisation-examples,
23
26
  ]
24
27
  related: [brick-input, brick-toggle, brick-template]
25
28
  ---
26
29
 
27
30
  # Brick Helloworld
28
31
 
29
- A demonstration component showcasing the anatomy and usage patterns of Brick components, used for testing and educational purposes.
32
+ A demonstration component showcasing the anatomy and usage patterns of Brick components, including server-side rendering, client-side rendering, template slots, component composition, and localisation (i18n).
30
33
 
31
34
  ## Key Capabilities
32
35
 
33
36
  - Demonstrates both server-side and client-side rendering patterns
34
- - Shows template processing with named template slots
37
+ - Supports localisation via `data-locale` attribute with `nb-NO`, `nn-NO`, and `da-DK` locales
35
38
  - Integrates with other Brick components (brick-input, brick-toggle)
36
- - Illustrates mirrored props and observed attributes
37
- - Provides examples of Stitches styling integration
39
+ - Shows template processing with named template slots
40
+ - Illustrates Stitches styling with typography variants via `data-version`
38
41
  - Serves as a reference implementation for new Brick components
39
42
 
40
43
  ## Props/Attributes
41
44
 
42
- | Attribute | Type | Default | Required | Description |
43
- | ------------------- | ------- | --------- | -------- | ------------------------------------------------------------- |
44
- | `data-text` | string | undefined | no | Text content to display in the component |
45
- | `data-version` | string | undefined | no | Version string used for styling variants |
46
- | `is-rendered` | boolean | false | no | Indicates if markup was rendered server-side |
47
- | `children-rendered` | string | undefined | no | Internal attribute set when child components finish rendering |
48
-
49
- ## Examples
50
-
51
- ### Basic Usage - Template Literals
52
-
53
- ```html
54
- <brick-helloworld-v2 data-text="Hello, World!" data-version="v2">
55
- <template name="content">
56
- <p>I am a paragraph inside a template named content</p>
57
- </template>
58
- </brick-helloworld-v2>
59
- ```
45
+ | Attribute | Type | Default | Required | Description |
46
+ | ------------------- | -------------------------------------- | ----------- | -------- | ----------------------------------------------------------------------------------- |
47
+ | `data-text` | `string` | `undefined` | no | Text content to display in the component |
48
+ | `data-version` | `"baseHeadlineXs" \| "baseMetaM" \| "baseMetaS" \| "baseHeadlineL" \| "baseHeadlineM" \| "baseBodyM"` | `"baseBodyM"` | no | Typography variant used for styling; maps to a Stitches variant in `styles.js` |
49
+ | `data-locale` | `"nb-NO" \| "nn-NO" \| "da-DK"` | `undefined` | no | Locale for translated text. Must be a supported locale or the component will throw |
50
+ | `is-rendered` | `boolean` | `false` | no | Indicates if markup was rendered server-side; prevents client-side DOM recreation |
51
+ | `children-rendered` | `string` | `undefined` | no | Internal attribute set when child components finish rendering; triggers template processing |
60
52
 
61
- ### JavaScript createElement
53
+ ## Usage
62
54
 
63
- ```javascript
64
- const el = document.createElement('brick-helloworld-v2');
65
- el.dataset.text = 'The quick brown fox jumps over the lazy dog';
66
- el.dataset.version = 'v2';
67
- document.body.appendChild(el);
68
- ```
55
+ ### Server-side rendering (preferred)
69
56
 
70
- ### Server-Side Rendering
57
+ Import the render function from the `/template` submodule and call it to produce an HTML string:
71
58
 
72
- ```javascript
59
+ ```ts
73
60
  import {
74
61
  renderBrickHelloworld,
75
62
  getCssText,
76
63
  } from '@amedia/brick-helloworld/template';
77
64
 
78
- const markup = renderBrickHelloworld({
79
- dataText: 'The quick brown fox jumps over the lazy dog',
80
- dataVersion: 'v2',
81
- isRendered: true,
65
+ const html = renderBrickHelloworld({
66
+ dataText: 'Hello, World!',
67
+ dataVersion: 'baseBodyM',
68
+ dataLocale: 'nb-NO',
82
69
  });
83
70
 
84
- // Include the styles
71
+ // Include the critical CSS for the component
85
72
  const css = `<style>${getCssText()}</style>`;
86
73
  ```
87
74
 
88
- ### Client-Side Import
75
+ When `isRendered` is omitted it defaults to `true` in the render function, which wraps the output in a `<brick-helloworld ...>` custom element tag with the `is-rendered` attribute. This prevents the client-side Web Component from recreating the DOM.
89
76
 
90
- ```javascript
91
- // Via npm
92
- import '@amedia/brick-helloworld';
77
+ #### SSR with a different locale
78
+
79
+ ```ts
80
+ const html = renderBrickHelloworld({
81
+ dataText: 'Hej verden!',
82
+ dataVersion: 'baseHeadlineM',
83
+ dataLocale: 'da-DK',
84
+ });
85
+ ```
86
+
87
+ #### SSR for client-side hydration only (no server markup)
93
88
 
94
- // Via Eik CDN
95
- import 'https://assets.acdn.no/pkg/@amedia/brick-helloworld/v2/brick-helloworld.js';
89
+ ```ts
90
+ const html = renderBrickHelloworld({
91
+ dataText: 'Will be rendered client-side',
92
+ dataVersion: 'baseBodyM',
93
+ dataLocale: 'nb-NO',
94
+ isRendered: false,
95
+ });
96
96
  ```
97
97
 
98
- ### Using Template Slots
98
+ ### Client-side (declarative HTML)
99
+
100
+ Use the custom element directly in HTML after registering the component:
99
101
 
100
102
  ```html
101
- <brick-helloworld-v2 data-text="Main content" data-version="v2">
103
+ <script
104
+ type="module"
105
+ src="https://assets.acdn.no/pkg/@amedia/brick-helloworld/v2/brick-helloworld.js"
106
+ ></script>
107
+
108
+ <brick-helloworld-v2
109
+ data-text="Hello, World!"
110
+ data-version="baseBodyM"
111
+ data-locale="nb-NO"
112
+ >
113
+ </brick-helloworld-v2>
114
+ ```
115
+
116
+ #### With template slots
117
+
118
+ ```html
119
+ <brick-helloworld-v2
120
+ data-text="Main content"
121
+ data-version="baseBodyM"
122
+ data-locale="nb-NO"
123
+ >
102
124
  <template name="content">
103
- <div class="custom-content">
104
- <h2>Custom Template Content</h2>
105
- <p>This content is processed by the component</p>
106
- </div>
125
+ <p>I am a paragraph inside a template named content</p>
107
126
  </template>
108
127
  </brick-helloworld-v2>
109
128
  ```
110
129
 
111
- ## Framework Integration
130
+ After the component's children have rendered (tracked via the `children-rendered` attribute), the component processes `<template name="content">` elements: it extracts the template content, wraps it in a `<div>`, appends it to the component, and removes the original `<template>` element.
112
131
 
113
- ### Node.js (>=18) - HTTPS Imports
114
-
115
- ```javascript
116
- // Using HTTPS imports (Node.js >= 18)
117
- import {
118
- renderBrickHelloworld,
119
- getCssText,
120
- } from 'https://assets.acdn.no/pkg/@amedia/brick-helloworld/v2/template.js';
132
+ #### JavaScript createElement
121
133
 
122
- const html = renderBrickHelloworld({
123
- dataText: 'Server rendered content',
124
- dataVersion: 'v2',
125
- });
134
+ ```js
135
+ const el = document.createElement('brick-helloworld-v2');
136
+ el.dataset.text = 'The quick brown fox jumps over the lazy dog';
137
+ el.dataset.version = 'baseBodyM';
138
+ el.dataset.locale = 'nb-NO';
139
+ document.body.appendChild(el);
126
140
  ```
127
141
 
128
- ## Programmatic Usage
129
-
130
- ```javascript
131
- import { BrickHelloworld } from '@amedia/brick-helloworld';
142
+ #### npm import
132
143
 
133
- const component = new BrickHelloworld();
134
- component.dataText = 'Programmatically set text';
135
- component.dataVersion = 'v2';
136
- document.body.appendChild(component);
144
+ ```js
145
+ import '@amedia/brick-helloworld';
137
146
  ```
138
147
 
139
- ## Common Patterns
148
+ ## Localisation
140
149
 
141
- ### Hybrid Server/Client Rendering
150
+ Added in version 2.1.0. The component supports localisation via `data-locale` and the `@amedia/brick-template` i18n utilities.
142
151
 
143
- When markup is rendered server-side with `isRendered: true`, the component will not recreate the DOM client-side but will still attach event listeners and process templates:
152
+ Supported locales and their translations for the `helloworld:text` key:
144
153
 
145
- ```html
146
- <!-- Server-rendered HTML -->
147
- <brick-helloworld-v2 data-version="v2" data-text="Content" is-rendered>
148
- <div class="hello-v2">
149
- Content
150
- <div class="hello-v2">v2</div>
151
- </div>
152
- <!-- Child components rendered server-side -->
153
- </brick-helloworld-v2>
154
+ | Locale | Translation |
155
+ | ------- | -------------------------- |
156
+ | `nb-NO` | Spraket er norsk bokmal |
157
+ | `nn-NO` | Spraket er norsk nynorsk |
158
+ | `da-DK` | Sproget er dansk |
154
159
 
155
- <!-- Client-side script -->
156
- <script
157
- type="module"
158
- src="https://assets.acdn.no/pkg/@amedia/brick-helloworld/v2/brick-helloworld.js"
159
- ></script>
160
- ```
160
+ The component calls `requireLocale()` which throws an error if an unsupported locale is provided. This is a deliberate fail-fast approach: the component will not silently fall back to a default locale.
161
161
 
162
- ### Template Processing
163
-
164
- The component demonstrates how to process named template slots and move content:
165
-
166
- ```javascript
167
- // Component processes template[name="content"]
168
- // and moves it into a div wrapper
169
- processTemplates() {
170
- const templateContent = this.querySelector('template[name="content"]');
171
- if (templateContent) {
172
- const range = document.createRange();
173
- range.selectNodeContents(templateContent.content);
174
- const contentWrapper = document.createElement('div');
175
- range.surroundContents(contentWrapper);
176
- this.appendChild(contentWrapper);
177
- templateContent.remove();
178
- }
179
- }
180
- ```
162
+ Translations are defined in `src/i18n.ts` and must conform to the `I18n` type from `@amedia/brick-template`.
181
163
 
182
- ### Component Composition
164
+ ## Accessibility
183
165
 
184
- Shows integration with other Brick components:
185
-
186
- ```html
187
- <brick-helloworld-v2 data-text="Form Example" data-version="v2">
188
- <!-- brick-input and brick-toggle are automatically included -->
189
- </brick-helloworld-v2>
190
- ```
166
+ - This is a development/demo component and does not implement specific ARIA patterns
167
+ - Child components (brick-input, brick-toggle) handle their own accessibility concerns
168
+ - Not intended for production use; accessibility testing is disabled in Storybook (`a11y: { disable: true }`)
191
169
 
192
170
  ## Technical Details
193
171
 
194
- - **Custom Element**: `brick-helloworld-v2`
195
- - **Base Class**: BrickElement (from @amedia/brick-template)
196
- - **Dependencies**: @amedia/brick-tokens, @amedia/brick-template, @amedia/brick-input, @amedia/brick-toggle
197
- - **Renders as**: Custom element with internal div structure
198
- - **Styling**: Stitches-based styling with variant support
199
- - **Mirrored Props**: `data-text`, `data-version` (automatically synced between attributes and properties)
172
+ - **Package version**: `2.1.0`
173
+ - **Custom Element tag**: `brick-helloworld-v2` -- must match the `selector` in frontmatter; the tag uses only the **major** version, not the full semver
174
+ - **Base Class**: `BrickElement` (from `@amedia/brick-template`)
175
+ - **Dependencies**: `@amedia/brick-tokens@6.2.2`, `@amedia/brick-template@2.1.0`, `@amedia/brick-input@4.0.9`, `@amedia/brick-toggle@3.1.34`
176
+ - **Mirrored Props**: `data-text`, `data-version` (automatically synced between HTML attributes and JS properties)
200
177
  - **Observed Attributes**: `children-rendered`
178
+ - **Styling**: Stitches-based via `@amedia/brick-tokens`; typography variants controlled by `data-version`
179
+ - **SSR export**: `@amedia/brick-helloworld/template` exports `renderBrickHelloworld` and `getCssText`
201
180
 
202
181
  ## Important Notes
203
182
 
204
- - This is a demonstration/example component primarily for development and testing purposes
205
- - Not intended for production use cases - serves as a reference implementation
206
- - Demonstrates the complete anatomy of a Brick component including build configuration
207
- - Used for testing release workflows, publishing, and build processes
208
- - Template processing occurs after children are rendered (via `children-rendered` attribute)
209
- - The component automatically includes brick-input and brick-toggle as child dependencies
210
- - Server-side rendering requires the `/template` export path
211
- - CSS is automatically injected when used client-side, but must be manually included for SSR via `getCssText()`
212
-
213
- ## Installation
214
-
215
- ```bash
216
- npm install @amedia/brick-helloworld
217
- ```
218
-
219
- ## Version
183
+ - This is a demonstration/example component for development and testing purposes; it is not intended for production use
184
+ - The `data-version` attribute controls typography styling variants, not the package version; valid values are Stitches variant keys like `baseBodyM`, `baseHeadlineL`, etc.
185
+ - `requireLocale()` will throw if `data-locale` is missing or unsupported -- this is intentional fail-fast behaviour
186
+ - Template processing (named `<template>` slots) occurs only after all children have rendered, triggered by the `children-rendered` attribute
187
+ - The component automatically includes brick-input and brick-toggle as child dependencies in both SSR and client-side modes
188
+ - Server-side rendering requires the `/template` export path; CSS must be manually included via `getCssText()`
189
+ - The package is ESM only -- there is no CommonJS export
220
190
 
221
- Current version: 2.0.2
191
+ ## Changelog (recent)
222
192
 
223
- ## Package Exports
193
+ ### 2.1.0
224
194
 
225
- - **ESM (Node)**: `dist/index.mjs`
226
- - **CommonJS (Node)**: `dist/index.js`
227
- - **Browser Bundle (Eik)**: `dist/eik/brick-helloworld.js`
228
- - **Template (SSR)**: `template/index.mjs`
195
+ - Added localisation support via `data-locale` attribute (proof of concept)
196
+ - Created component-specific translations in `src/i18n.ts`
197
+ - Updated dependency on `@amedia/brick-template@2.1.0` which provides `getTranslation`, `requireLocale`, `SupportedLocales` type, and `I18n` type