|
1 |
| -<script> |
2 |
| - import SettingItem from "@/libs/setting-item.svelte"; |
3 |
| - import { showMessage } from "siyuan"; |
4 |
| - import { onMount, onDestroy } from 'svelte'; |
5 |
| - onMount(() => { |
6 |
| - showMessage("Setting panel opened"); |
7 |
| - }); |
8 |
| - onDestroy(() => { |
9 |
| - showMessage("Setting panel closed"); |
10 |
| - }); |
11 |
| -</script> |
| 1 | +<script lang="ts"> |
| 2 | + import SettingPanel from "./libs/setting-panel.svelte"; |
| 3 | +
|
| 4 | + let groups: string[] = ["🌈 Default"]; |
| 5 | + let focusGroup = groups[0]; |
12 | 6 |
|
13 |
| -<!-- |
14 |
| -You can use this template to quickly create a setting panel, |
15 |
| -with the same UI style in SiYuan |
16 |
| ---> |
| 7 | + const SettingItems: ISettingItem[] = [ |
| 8 | + { |
| 9 | + type: 'checkbox', |
| 10 | + title: 'checkbox', |
| 11 | + description: 'checkbox', |
| 12 | + key: 'a', |
| 13 | + value: true |
| 14 | + }, |
| 15 | + { |
| 16 | + type: 'textinput', |
| 17 | + title: 'text', |
| 18 | + description: 'This is a text', |
| 19 | + key: 'b', |
| 20 | + value: 'This is a text', |
| 21 | + placeholder: 'placeholder' |
| 22 | + }, |
| 23 | + { |
| 24 | + type: 'select', |
| 25 | + title: 'select', |
| 26 | + description: 'select', |
| 27 | + key: 'c', |
| 28 | + value: 'x', |
| 29 | + options: { |
| 30 | + x: 'x', |
| 31 | + y: 'y', |
| 32 | + z: 'z' |
| 33 | + } |
| 34 | + }, |
| 35 | + { |
| 36 | + type: 'slider', |
| 37 | + title: 'slider', |
| 38 | + description: 'slider', |
| 39 | + key: 'd', |
| 40 | + value: 50, |
| 41 | + slider: { |
| 42 | + min: 0, |
| 43 | + max: 100, |
| 44 | + step: 1 |
| 45 | + } |
| 46 | + } |
| 47 | + ]; |
17 | 48 |
|
18 |
| -<div class="config__tab-container"> |
19 |
| - <div data-type="Header" class="fn__flex b3-label"> |
20 |
| - <div class="fn_flex-1"> |
21 |
| - <h4>This setting panel is provided by a svelte component</h4> |
22 |
| - <div class="b3-label__text"> |
23 |
| - <span class="fn__flex-1"> |
24 |
| - See: |
25 |
| - <pre style="display: inline">/lib/setting-pannel.svelte</pre> |
26 |
| - </span> |
| 49 | + /********** Events **********/ |
| 50 | + interface ChangeEvent { |
| 51 | + group: string; |
| 52 | + key: string; |
| 53 | + value: any; |
| 54 | + } |
| 55 | +
|
| 56 | + const onChanged = ({ detail }: CustomEvent<ChangeEvent>) => { |
| 57 | + if (detail.group === groups[0]) { |
| 58 | + // setting.set(detail.key, detail.value); |
| 59 | + } |
| 60 | + }; |
| 61 | +</script> |
| 62 | + |
| 63 | +<div class="fn__flex-1 fn__flex config__panel"> |
| 64 | + <ul class="b3-tab-bar b3-list b3-list--background"> |
| 65 | + {#each groups as group} |
| 66 | + <li |
| 67 | + data-name="editor" |
| 68 | + class:b3-list-item--focus={group === focusGroup} |
| 69 | + class="b3-list-item" |
| 70 | + on:click={() => { |
| 71 | + focusGroup = group; |
| 72 | + }} |
| 73 | + on:keydown={() => {}} |
| 74 | + > |
| 75 | + <span class="b3-list-item__text">{group}</span> |
| 76 | + </li> |
| 77 | + {/each} |
| 78 | + </ul> |
| 79 | + <div class="config__tab-wrap"> |
| 80 | + <SettingPanel |
| 81 | + group={groups[0]} |
| 82 | + settingItems={SettingItems} |
| 83 | + display={focusGroup === groups[0]} |
| 84 | + on:changed={onChanged} |
| 85 | + > |
| 86 | + <div class="fn__flex b3-label"> |
| 87 | + 💡 This is our default settings. |
27 | 88 | </div>
|
28 |
| - </div> |
| 89 | + </SettingPanel> |
29 | 90 | </div>
|
30 |
| - <SettingItem |
31 |
| - type="checkbox" |
32 |
| - title="Checkbox" |
33 |
| - description="This is a <b>checkbox</b>" |
34 |
| - settingKey="Checkbox" |
35 |
| - settingValue={true} |
36 |
| - on:changed={(event) => { |
37 |
| - showMessage( |
38 |
| - `Checkbox changed: ${event.detail.key} = ${event.detail.value}` |
39 |
| - ); |
40 |
| - }} |
41 |
| - /> |
42 |
| - <SettingItem |
43 |
| - type="input" |
44 |
| - title="Input" |
45 |
| - description="This is an input" |
46 |
| - settingKey="Input" |
47 |
| - settingValue="" |
48 |
| - placeholder="Input something" |
49 |
| - on:changed={(event) => { |
50 |
| - showMessage( |
51 |
| - `Input changed: ${event.detail.key} = ${event.detail.value}` |
52 |
| - ); |
53 |
| - }} |
54 |
| - /> |
55 |
| - <SettingItem |
56 |
| - type="button" |
57 |
| - title="Button" |
58 |
| - description="This is a button" |
59 |
| - settingKey="Button" |
60 |
| - settingValue="Click me" |
61 |
| - on:clicked={() => { |
62 |
| - showMessage("Button clicked"); |
63 |
| - }} |
64 |
| - /> |
65 |
| - <SettingItem |
66 |
| - type="select" |
67 |
| - title="Select" |
68 |
| - description="This is a select" |
69 |
| - settingKey="Select" |
70 |
| - settingValue="left" |
71 |
| - options={{ |
72 |
| - left: "Left", |
73 |
| - center: "Center", |
74 |
| - right: "Right", |
75 |
| - }} |
76 |
| - on:changed={(event) => { |
77 |
| - showMessage( |
78 |
| - `Select changed: ${event.detail.key} = ${event.detail.value}` |
79 |
| - ); |
80 |
| - }} |
81 |
| - /> |
82 |
| - <SettingItem |
83 |
| - type="slider" |
84 |
| - title="Slide" |
85 |
| - description="This is a slide" |
86 |
| - settingKey="Slide" |
87 |
| - settingValue={50} |
88 |
| - slider={{ |
89 |
| - min: 0, |
90 |
| - max: 100, |
91 |
| - step: 1, |
92 |
| - }} |
93 |
| - on:changed={(event) => { |
94 |
| - showMessage( |
95 |
| - `Slide changed: ${event.detail.key} = ${event.detail.value}` |
96 |
| - ); |
97 |
| - }} |
98 |
| - /> |
99 | 91 | </div>
|
| 92 | + |
| 93 | +<style lang="scss"> |
| 94 | + .config__panel { |
| 95 | + height: 100%; |
| 96 | + } |
| 97 | + .config__panel > ul > li { |
| 98 | + padding-left: 1rem; |
| 99 | + } |
| 100 | +</style> |
| 101 | + |
0 commit comments