|
1 | 1 | import {render} from 'preact'; |
2 | 2 | import {ConsentsMap} from '../core/types'; |
3 | 3 | import Manager from '../core/Manager'; |
4 | | -import {Config} from './types'; |
| 4 | +import {Config, TitleLevel} from './types'; |
5 | 5 | import Context from './components/Context'; |
6 | 6 | import ContextualNoticeContainer from './components/ContextualNoticeContainer'; |
7 | 7 | import ConsentsEffect from '../core/ConsentsEffect'; |
| 8 | +import {clamp} from './utils/numbers'; |
8 | 9 |
|
9 | 10 | export default class ContextualConsentsEffect implements ConsentsEffect { |
10 | 11 | readonly #config: Config; |
@@ -36,15 +37,27 @@ export default class ContextualConsentsEffect implements ConsentsEffect { |
36 | 37 | }} |
37 | 38 | > |
38 | 39 | <ContextualNoticeContainer |
39 | | - purposeId={template.dataset.purpose} |
40 | | - data={{...template.dataset}} |
| 40 | + {...this.#parseNoticeData(template.dataset)} |
41 | 41 | isEnabled={isEnabled} |
42 | 42 | /> |
43 | 43 | </Context.Provider>, |
44 | 44 | this.#getNoticeContainer(template) |
45 | 45 | ); |
46 | 46 | } |
47 | 47 |
|
| 48 | + #parseNoticeData(data: DOMStringMap) { |
| 49 | + return { |
| 50 | + purposeId: data.purpose, |
| 51 | + titleLevel: clamp( |
| 52 | + parseInt(data.titleLevel, 10) |
| 53 | + || this.#config?.contextual?.defaultTitleLevel |
| 54 | + || 6, |
| 55 | + 1, |
| 56 | + 6 |
| 57 | + ) as TitleLevel |
| 58 | + }; |
| 59 | + } |
| 60 | + |
48 | 61 | #getNoticeContainer(template: HTMLTemplateElement) { |
49 | 62 | if (!this.#containers.has(template)) { |
50 | 63 | const container = document.createElement('div'); |
|
0 commit comments