|
1 | 1 | --- |
2 | 2 | title: Consent |
3 | | -description: "A consent banner and preference panel driven by the site’s categories, policy version and service configuration." |
| 3 | +description: "Let visitors choose which optional cookies and services your site may use, and change their preferences later." |
4 | 4 | template: doc |
5 | 5 | layout: |
6 | 6 | showNav: true |
|
16 | 16 | <ComponentHeader |
17 | 17 | name="Consent" |
18 | 18 | kind="Privacy preferences" |
19 | | - summary="A consent banner and preference panel driven by the site’s categories, policy version and service configuration." |
| 19 | + summary="Let visitors choose which optional cookies and services your site may use, and change their preferences later." |
20 | 20 | source="https://github.com/PureStackStudio/PureStack/blob/main/packages/ts-components/src/standard/consent/consent.ts" |
21 | 21 | section="Site navigation & services" |
22 | 22 | sectionHref="/components/site/"/> |
23 | 23 |
|
| 24 | +Consent gives visitors control over optional cookies and services, such as |
| 25 | +analytics or marketing. Its banner offers **Accept all**, **Reject non-essential**, |
| 26 | +and **Manage preferences**. The preferences panel lets visitors choose individual |
| 27 | +categories while required categories stay enabled. |
| 28 | + |
| 29 | +Consent remembers the saved choice and loads configured optional services only |
| 30 | +after permission is granted. Visitors can reopen preferences using either option |
| 31 | +above, change their choices, and save again. |
| 32 | + |
| 33 | +## Open privacy preferences |
| 34 | + |
| 35 | +With consent enabled in your site configuration, Consent is included |
| 36 | +automatically. Choose either of these two ways to let visitors reopen their |
| 37 | +preferences after making a choice. |
| 38 | + |
| 39 | +### 1. Use your own button or link |
| 40 | + |
| 41 | +Add `data-consent-action="open-panel"` to a `Btn` or `BtnLink` in your footer, |
| 42 | +navigation, or page content. Clicking it opens the privacy preferences panel. |
| 43 | + |
| 44 | +For a button: |
| 45 | + |
| 46 | +```html |
| 47 | +<Btn tone="neutral" variant="outline" data-consent-action="open-panel"> |
| 48 | + Manage privacy settings |
| 49 | +</Btn> |
| 50 | +``` |
| 51 | + |
| 52 | +For a link: |
| 53 | + |
| 54 | +```html |
| 55 | +<BtnLink |
| 56 | + href="/legal/privacy/" |
| 57 | + tone="neutral" |
| 58 | + variant="link" |
| 59 | + data-consent-action="open-panel" |
| 60 | +> |
| 61 | + Privacy settings |
| 62 | +</BtnLink> |
| 63 | +``` |
| 64 | + |
| 65 | +### 2. Use the default teleport area |
| 66 | + |
| 67 | +Place this empty element where you want the default **Privacy settings** button |
| 68 | +to appear: |
| 69 | + |
| 70 | +```html |
| 71 | +<span class="consent-settings-teleport-area"></span> |
| 72 | +``` |
| 73 | + |
| 74 | +Consent automatically places its settings button inside that element. |
| 75 | +SiteFooter already provides this area. If the area is absent, Consent does not |
| 76 | +add a settings button. |
| 77 | + |
| 78 | + |
24 | 79 | ## Make and revise a choice |
25 | 80 |
|
26 | 81 | This preview uses this site's real consent settings and shares its saved privacy choice. Open settings to review the configured categories. |
@@ -124,47 +179,35 @@ Use the working example to open, save, close, and reopen this site's real privac |
124 | 179 | </div> |
125 | 180 | </ComponentExample> |
126 | 181 |
|
127 | | -## Configuration and service activation |
| 182 | +## Configuration |
128 | 183 |
|
129 | 184 | | Configuration | Visible role | |
130 | 185 | | --- | --- | |
131 | 186 | | enabled | Determines whether the component renders. | |
132 | | -| storageKey, policyVersion | Keep the example separate and invalidate outdated choices. | |
| 187 | +| storageKey, policyVersion | Set where choices are saved and when visitors must make a fresh choice. | |
133 | 188 | | categories | Give each category an ID, label, description, and required flag. | |
134 | | -| services | Associate a service with its consent category; optional services wait for permission. The example uses no tracking services. | |
| 189 | +| services | Associate each optional service with the category that gives it permission to load. | |
135 | 190 | | Banner, action, and settings labels | Customize the language of the banner, buttons, and preferences. | |
136 | 191 | | privacyPolicyUrl, privacyPolicyLabel | Add the policy destination beside the banner copy. | |
137 | | -| Footer settings target | The settings control teleports to .consent-settings-teleport-area. | |
138 | | - |
139 | | -Appearance galleries show the actual banner markup with every treatment. They are static comparisons; the isolated example above runs the full consent flow. |
140 | | - |
141 | | -## Feature map |
142 | | - |
143 | | -| Feature | Where to explore it | |
144 | | -| --- | --- | |
145 | | -| Banner choices, required and optional categories, saved settings, and services | Context preview, feature comparisons, and original copyable source examples. | |
146 | | -| Public appearance options | Complete galleries above. Only options supported by this component are shown. | |
147 | | -| Native semantics and integration | Behavior notes and API contracts below explain the component’s roots, slots, and runtime dependencies. | |
148 | | - |
149 | | -## Behavior and accessibility |
150 | 192 |
|
151 | | -Consent renders only when site.consent.enabled is true. The runtime opens the banner when no current saved choice exists, persists choices under storageKey and uses policyVersion to identify the policy. Necessary categories remain selected. Keep labels and descriptions specific to the services your site actually runs. |
| 193 | +Keep category labels and descriptions specific to the services your site uses. |
152 | 194 |
|
153 | 195 | ## API reference |
154 | 196 |
|
155 | 197 | <div class="api-overview"> |
156 | 198 | <p class="text-eyebrow">Consent contract</p> |
157 | 199 | <p> |
158 | | - The three public props style the component. Banner copy, categories, |
159 | | - storage, policy version and services come from site.consent, not markup |
160 | | - props. |
| 200 | + Appearance props style the component; settingsTeleport places its settings |
| 201 | + button. Banner copy, categories, storage, policy version and services come |
| 202 | + from site.consent, not markup props. |
161 | 203 | </p> |
162 | 204 | </div> |
163 | 205 |
|
164 | 206 | <nav class="api-index" aria-label="Consent properties"> |
165 | 207 | <a href="#consent-prop-tone">tone</a> |
166 | 208 | <a href="#consent-prop-variant">variant</a> |
167 | 209 | <a href="#consent-prop-variantMode">variantMode</a> |
| 210 | + <a href="#consent-prop-settingsTeleport">settingsTeleport</a> |
168 | 211 | </nav> |
169 | 212 |
|
170 | 213 | <ApiProperty |
@@ -204,28 +247,30 @@ Consent renders only when site.consent.enabled is true. The runtime opens the ba |
204 | 247 | </p> |
205 | 248 | </ApiProperty> |
206 | 249 |
|
| 250 | +<ApiProperty |
| 251 | + anchor="consent-prop-settingsTeleport" |
| 252 | + name="settingsTeleport" |
| 253 | + valueType="string" |
| 254 | + defaultValue=".consent-settings-teleport-area" |
| 255 | +> |
| 256 | + <p> |
| 257 | + CSS selector for the built-in settings button's destination. Provide the |
| 258 | + target before Consent renders. An empty selector or a missing target omits |
| 259 | + the button; the banner and preference panel remain available. |
| 260 | + </p> |
| 261 | +</ApiProperty> |
| 262 | + |
207 | 263 | ### Composition |
208 | 264 |
|
209 | 265 | <div class="api-contract"> |
210 | 266 | <p> |
211 | | - No public slots. The settings button teleports to |
212 | | - .consent-settings-teleport-area, provided by SiteFooter or by your own |
213 | | - template. Register defineConsentComponents with Panel, Flex, Btn, BtnLink |
214 | | - and FormCheck. Include the standard consent runtime with the same resolved |
215 | | - configuration. |
| 267 | + Consent is included automatically when enabled. Use a Btn or BtnLink with |
| 268 | + data-consent-action="open-panel" to open preferences, or provide |
| 269 | + .consent-settings-teleport-area for the default settings button. No public |
| 270 | + slots. |
216 | 271 | </p> |
217 | 272 | </div> |
218 | 273 |
|
219 | | -### Configuration responsibilities |
220 | | - |
221 | | -- `enabled` controls whether the component exists. |
222 | | -- `storageKey` isolates saved choices; `policyVersion` identifies the current policy. |
223 | | -- `categories` define IDs, visible labels, descriptions and required state. |
224 | | -- `services` describe the services controlled by those categories. |
225 | | -- Banner, button and policy-link copy belong in the consent configuration. |
226 | | - |
227 | | -The preview source shows the complete scoped override used by the working example. |
228 | | - |
229 | 274 | ## Related components |
230 | 275 |
|
231 | 276 | - [SiteFooter](/components/site/site-footer/) |
|
0 commit comments