|
1 | 1 | import React, { useEffect, useState } from 'react'; |
2 | | -import { IconContext } from 'react-icons'; |
3 | | -import { MdOutlineColorLens } from 'react-icons/md'; |
4 | | -import Select, { ActionMeta, SingleValue } from 'react-select'; |
5 | | -import Switch from 'react-switch'; |
6 | 2 | import styled from 'styled-components'; |
7 | 3 | import { IndentOptionsType } from '../utils/types'; |
8 | 4 | import { Demonstration } from './Demonstration'; |
9 | | - |
10 | | -const options = [ |
11 | | - { value: '●', label: '●' }, |
12 | | - { value: '○', label: '○' }, |
13 | | - { value: '■', label: '■' }, |
14 | | - { value: '□', label: '□' }, |
15 | | -]; |
| 5 | +import { MakerConsole } from './MakerConsole'; |
16 | 6 |
|
17 | 7 | const initialState: IndentOptionsType = [ |
18 | 8 | { value: '●', label: 'indent-1' }, |
@@ -67,143 +57,21 @@ export const Console: React.FC<Props> = () => { |
67 | 57 | }); |
68 | 58 | }; |
69 | 59 |
|
70 | | - const handleOnChange = ( |
71 | | - newValue: SingleValue<{ |
72 | | - value: string; |
73 | | - label: string; |
74 | | - }>, |
75 | | - metaAction: ActionMeta<{ |
76 | | - value: string; |
77 | | - label: string; |
78 | | - }> |
79 | | - ) => { |
80 | | - // eslint-disable-next-line |
81 | | - const value = newValue!.value; |
82 | | - const label = metaAction.name; |
83 | | - |
84 | | - const newIndentOptions = indentOptions.map((option) => { |
85 | | - if (option.label === label) { |
86 | | - return { value, label }; |
87 | | - } |
88 | | - return option; |
89 | | - }); |
90 | | - |
91 | | - setIndentOptions(newIndentOptions); |
92 | | - |
93 | | - chrome.storage.local.set({ scrapboxIndentOption: newIndentOptions }); |
94 | | - |
95 | | - chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { |
96 | | - tabs.forEach((tab) => { |
97 | | - if (tab.url === undefined || tab.id === undefined) return; |
98 | | - const url = new URL(tab.url); |
99 | | - if (url.hostname === 'scrapbox.io') { |
100 | | - chrome.tabs.sendMessage(tab.id, 'scrapbox_list_maker'); |
101 | | - } |
102 | | - }); |
103 | | - }); |
104 | | - }; |
105 | | - |
106 | 60 | return ( |
107 | 61 | <MainContainer> |
108 | | - <TitleWrapper> |
109 | | - <Title>Select Favorite Maker</Title> |
110 | | - <SwitchLabel> |
111 | | - <Switch |
112 | | - checked={indentLining} |
113 | | - onChange={handleIndentLiningChange} |
114 | | - onColor="#00b428" |
115 | | - boxShadow="0px 1px 5px rgba(0, 0, 0, 0.6)" |
116 | | - height={16} |
117 | | - width={30} |
118 | | - handleDiameter={18} |
119 | | - checkedIcon={false} |
120 | | - uncheckedIcon={false} |
121 | | - /> |
122 | | - <Spacer width={6} /> |
123 | | - <span>Indent Visible</span> |
124 | | - </SwitchLabel> |
125 | | - <IconContext.Provider |
126 | | - value={{ size: '20px', style: { padding: '2px' } }} |
127 | | - > |
128 | | - <ColorLens /> |
129 | | - </IconContext.Provider> |
130 | | - </TitleWrapper> |
131 | | - <IndentContainer> |
132 | | - {indentOptions.map((indentOption) => { |
133 | | - const spaceNum = +indentOption.label.replace(/[^0-9]/g, '') - 1; |
134 | | - |
135 | | - return ( |
136 | | - <> |
137 | | - <IndentRow spaceNum={spaceNum}> |
138 | | - <Select |
139 | | - value={{ |
140 | | - value: indentOption.value, |
141 | | - label: indentOption.value, |
142 | | - }} |
143 | | - onChange={handleOnChange} |
144 | | - key={indentOption.label} |
145 | | - name={indentOption.label} |
146 | | - options={options} |
147 | | - ></Select> |
148 | | - <Label>{indentOption.label}</Label> |
149 | | - </IndentRow> |
150 | | - </> |
151 | | - ); |
152 | | - })} |
153 | | - </IndentContainer> |
| 62 | + <MakerConsole |
| 63 | + indentOptions={indentOptions} |
| 64 | + setIndentOptions={setIndentOptions} |
| 65 | + indentLining={indentLining} |
| 66 | + handleIndentLiningChange={handleIndentLiningChange} |
| 67 | + /> |
154 | 68 | <Demonstration hasLine={indentLining} indentOptions={indentOptions} /> |
155 | 69 | </MainContainer> |
156 | 70 | ); |
157 | 71 | }; |
158 | 72 |
|
159 | | -const ColorLens = styled(MdOutlineColorLens)` |
160 | | - color: #00b428; |
161 | | - :hover { |
162 | | - color: #b4008c; |
163 | | - cursor: pointer; |
164 | | - } |
165 | | -`; |
166 | | - |
167 | 73 | const MainContainer = styled.div` |
168 | 74 | background-color: #dcdde0; |
169 | 75 | padding: 4px; |
170 | 76 | padding-bottom: 8px; |
171 | 77 | `; |
172 | | - |
173 | | -const Spacer = styled.div<{ width: number }>` |
174 | | - width: ${(props) => props.width}px; |
175 | | -`; |
176 | | - |
177 | | -const TitleWrapper = styled.div` |
178 | | - display: flex; |
179 | | - align-items: center; |
180 | | -`; |
181 | | - |
182 | | -const Title = styled.div` |
183 | | - font-size: 16px; |
184 | | - text-align: left; |
185 | | - margin: 10px 12px; |
186 | | -`; |
187 | | - |
188 | | -const SwitchLabel = styled.label` |
189 | | - margin-left: 8px; |
190 | | - display: flex; |
191 | | - align-items: center; |
192 | | -`; |
193 | | - |
194 | | -const Label = styled.div` |
195 | | - font-size: 14px; |
196 | | - margin-left: 12px; |
197 | | -`; |
198 | | - |
199 | | -const IndentContainer = styled.div` |
200 | | - margin: 0px 10px; |
201 | | -`; |
202 | | - |
203 | | -const IndentRow = styled.div<{ spaceNum: number }>` |
204 | | - margin-left: ${(props) => `${props.spaceNum * 30}px`}; |
205 | | - margin-top: 4px; |
206 | | - margin-bottom: 4px; |
207 | | - display: flex; |
208 | | - align-items: center; |
209 | | -`; |
0 commit comments