Repository navigation
Expand file tree
/
Copy pathsettings.html
More file actions
197 lines (171 loc) · 7.94 KB
/
Copy pathsettings.html
File metadata and controls
197 lines (171 loc) · 7.94 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Settings - rnxJS</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Archivo:wght@600;700&family=JetBrains+Mono:wght@400;500&family=Public+Sans:wght@400;500;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="demo.css">
</head>
<body>
<div class="topbar">
<div class="shell topbar-in mono">
<a class="wordmark" href="./" style="color:inherit;text-decoration:none">rnxJS</a>
<span class="sep">/</span>
<span>settings</span>
<span class="spacer"></span>
<a class="chan" href="./"><i class="bi bi-arrow-left"></i> All demos</a>
</div>
</div>
<div class="shell">
<header class="page-head">
<div class="titles">
<h1>Workspace settings</h1>
<p class="sub">
Switches, selects and inputs, all rnxJS components bound to one
reactive state object.
</p>
</div>
<div class="page-actions" data-ref="actions"></div>
</header>
<section class="grid-sidebar">
<nav class="panel">
<div class="side-nav" data-ref="nav"></div>
</nav>
<div class="panel">
<div class="panel-head">
<h2 data-ref="paneTitle">Profile</h2>
<p class="hint" data-ref="paneHint"></p>
</div>
<div class="panel-body" data-ref="pane"></div>
</div>
</section>
</div>
<footer style="margin-top:2.5rem">
<div class="shell" style="display:flex;gap:1.25rem;flex-wrap:wrap;align-items:center;">
<span class="mono" data-ref="footVersion">rnxJS</span>
<a href="./">All demos</a>
<a href="https://github.com/BaryoDev/rnxJS_samples">Source</a>
<span style="margin-left:auto" class="mono">MPL-2.0</span>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/@arnelirobles/rnxjs@2.3.1/dist/rnx.global.js"></script>
<script>
const { Button, Input, Textarea, Select, Switch, createReactiveState } = rnx;
const $ = (ref) => document.querySelector(`[data-ref="${ref}"]`);
const state = createReactiveState({
fullName: 'Rina Okafor',
email: 'rina@northwind-freight.com',
role: 'Support lead',
bio: 'Runs the EU support rota. Owns the escalation policy.',
theme: 'system',
density: 'comfortable',
digest: 'daily',
notifyAssigned: true,
notifyMentions: true,
notifyDigest: false,
twoFactor: true,
sessionTimeout: '30',
});
const SECTIONS = [
['profile', 'Profile', 'How you appear to your team'],
['appearance', 'Appearance', 'Applies to this browser only'],
['notifications', 'Notifications', 'What reaches you, and when'],
['security', 'Security', 'Sign-in and session policy'],
];
// ---- fields --------------------------------------------------------
const field = (label, control, wide) => {
const w = document.createElement('div');
w.className = 'field' + (wide ? ' wide' : '');
const l = document.createElement('label');
l.textContent = label;
w.append(l, control);
return w;
};
const row = (...kids) => {
const g = document.createElement('div');
g.className = 'form-grid';
g.append(...kids);
return g;
};
const toggle = (label, hint, key) => {
const w = document.createElement('div');
w.className = 'toggle-row';
const t = document.createElement('div');
t.className = 'toggle-text';
t.innerHTML = `<span class="toggle-label">${label}</span><span class="toggle-hint">${hint}</span>`;
const s = Switch({ checked: state[key], onchange: (v) => { state[key] = !!v; } });
w.append(t, s);
return w;
};
const PANES = {
profile: () => [
row(
field('Full name', Input({ value: state.fullName })),
field('Email', Input({ value: state.email, type: 'email' })),
field('Role', Input({ value: state.role })),
),
row(field('Short bio', Textarea({ value: state.bio, rows: 3 }), true)),
],
appearance: () => [
row(
field('Theme', Select({
value: state.theme,
options: [{ value: 'system', label: 'Match system' }, { value: 'light', label: 'Light' }, { value: 'dark', label: 'Dark' }],
})),
field('Row density', Select({
value: state.density,
options: [{ value: 'comfortable', label: 'Comfortable' }, { value: 'compact', label: 'Compact' }],
})),
),
],
notifications: () => [
toggle('Ticket assigned to me', 'Email and in-app, immediately', 'notifyAssigned'),
toggle('Mentioned in a thread', 'In-app only', 'notifyMentions'),
toggle('Daily digest', 'One summary at 08:00 in your timezone', 'notifyDigest'),
row(field('Digest frequency', Select({
value: state.digest,
options: [{ value: 'daily', label: 'Daily' }, { value: 'weekly', label: 'Weekly' }, { value: 'off', label: 'Off' }],
}))),
],
security: () => [
toggle('Two-factor authentication', 'Required for everyone on this workspace', 'twoFactor'),
row(field('Sign out after inactivity', Select({
value: state.sessionTimeout,
options: [{ value: '15', label: '15 minutes' }, { value: '30', label: '30 minutes' }, { value: '480', label: '8 hours' }],
}))),
],
};
// ---- render --------------------------------------------------------
let current = 'profile';
function showPane(key) {
current = key;
const [, title, hint] = SECTIONS.find(s => s[0] === key);
$('paneTitle').textContent = title;
$('paneHint').textContent = hint;
$('pane').replaceChildren(...PANES[key]());
[...$('nav').children].forEach(a =>
a.setAttribute('aria-current', String(a.dataset.key === key)));
}
// Links rather than buttons: these navigate, and a plain <button> is
// currently replaced by an rnxJS Button (BaryoDev/rnxjs#49).
$('nav').innerHTML = SECTIONS.map(([key, title]) =>
`<a href="#${key}" data-key="${key}">${title}</a>`).join('');
$('nav').addEventListener('click', (e) => {
const a = e.target.closest('[data-key]');
if (!a) return;
e.preventDefault();
showPane(a.dataset.key);
});
$('actions').append(Button({ label: 'Save changes', icon: 'check-lg', variant: 'primary' }));
showPane('profile');
const build = (document.documentElement.dataset.rnxVersion || '').trim();
if (build) $('footVersion').textContent = 'rnxJS ' + build;
</script>
</body>
</html>