-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy paththemeOptions.ts
More file actions
90 lines (81 loc) · 2.72 KB
/
Copy paththemeOptions.ts
File metadata and controls
90 lines (81 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { insertRadioButton } from './radioButton';
const themeOptionsHtml = `
<div class='flex flex-col gap-2'>
<label class='subheading' htmlFor='theme'>Change Theme</label>
<div id="theme-options" class='flex gap-2 font-bold'></div>
<p class='paragraph'>
Documentation for customizing themes are
<a
href='https://docs.corbado.com/frontend-integration/ui-components/less-than-corbadoprovider-greater-than#custom-themes'
target='_blank'
class='text-blue-600'
>
here
</a>
</p>
</div>`;
const updateRadioButtons = (value: string) => {
const basicTheme = document.getElementById('basic-theme') as HTMLInputElement;
const emeraldFunkTheme = document.getElementById('cb-emerald-funk-theme') as HTMLInputElement;
const corbadoCustomTheme = document.getElementById('corbado-custom-theme') as HTMLInputElement;
if (document.body.classList.contains('cb-emerald-funk-theme')) {
document.body.classList.remove('cb-emerald-funk-theme');
} else if (document.body.classList.contains('corbado-custom-theme')) {
document.body.classList.remove('corbado-custom-theme');
}
switch (value) {
case '':
basicTheme.checked = true;
emeraldFunkTheme.checked = false;
corbadoCustomTheme.checked = false;
break;
case 'cb-emerald-funk-theme':
basicTheme.checked = false;
emeraldFunkTheme.checked = true;
corbadoCustomTheme.checked = false;
break;
case 'corbado-custom-theme':
basicTheme.checked = false;
emeraldFunkTheme.checked = false;
corbadoCustomTheme.checked = true;
break;
}
};
export function insertThemeOptions(initialValue: string, onThemeChange: (value: string) => void) {
const demoComponent = document.getElementById('demo');
const optionsElement = demoComponent!.appendChild(document.createElement('div'));
optionsElement.setAttribute('class', 'flex mt-8 flex-col gap-2');
optionsElement.innerHTML = themeOptionsHtml;
const options = document.getElementById('theme-options');
console.log('theme initial value:', initialValue);
insertRadioButton(
'basic-theme',
options!,
() => {
updateRadioButtons('');
onThemeChange('');
},
'Basic',
!initialValue,
);
insertRadioButton(
'cb-emerald-funk-theme',
options!,
() => {
updateRadioButtons('cb-emerald-funk-theme');
onThemeChange('cb-emerald-funk-theme');
},
'Emerald Funk',
initialValue === 'cb-emerald-funk-theme',
);
insertRadioButton(
'corbado-custom-theme',
options!,
() => {
updateRadioButtons('corbado-custom-theme');
onThemeChange('corbado-custom-theme');
},
'Customized Theme',
initialValue === 'corbado-custom-theme',
);
}