11import React , { useEffect , useState } from 'react' ;
2- import Select , { ActionMeta , SingleValue } from 'react-select' ;
3- import Switch from 'react-switch' ;
42import styled from 'styled-components' ;
53import { IndentOptionsType } from '../utils/types' ;
64import { Demonstration } from './Demonstration' ;
7-
8- const options = [
9- { value : '●' , label : '●' } ,
10- { value : '○' , label : '○' } ,
11- { value : '■' , label : '■' } ,
12- { value : '□' , label : '□' } ,
13- ] ;
5+ import { MakerConsole } from './MakerConsole' ;
146
157const initialState : IndentOptionsType = [
168 { value : '●' , label : 'indent-1' } ,
@@ -25,6 +17,7 @@ export const Console: React.FC<Props> = () => {
2517 const [ indentOptions , setIndentOptions ] =
2618 useState < IndentOptionsType > ( initialState ) ;
2719 const [ indentLining , setIndentLining ] = useState < boolean > ( false ) ;
20+ const [ indentLiningColor , setIndentLiningColor ] = useState < string > ( '#dcdcdc' ) ;
2821
2922 useEffect ( ( ) => {
3023 chrome . storage . local . get ( 'scrapboxIndentOption' , ( result ) => {
@@ -48,6 +41,17 @@ export const Console: React.FC<Props> = () => {
4841 setIndentLining ( scrapboxIndentLining ) ;
4942 }
5043 } ) ;
44+
45+ chrome . storage . local . get ( 'scrapboxIndentLineColor' , ( result ) => {
46+ const scrapboxIndentLineColor = result . scrapboxIndentLineColor ;
47+
48+ if ( ! scrapboxIndentLineColor ) {
49+ chrome . storage . local . set ( { scrapboxIndentLineColor : '#dcdcdc' } ) ;
50+ setIndentLiningColor ( '#dcdcdc' ) ;
51+ } else {
52+ setIndentLiningColor ( scrapboxIndentLineColor ) ;
53+ }
54+ } ) ;
5155 } , [ ] ) ;
5256
5357 const handleIndentLiningChange = ( checked : boolean ) => {
@@ -65,86 +69,20 @@ export const Console: React.FC<Props> = () => {
6569 } ) ;
6670 } ;
6771
68- const handleOnChange = (
69- newValue : SingleValue < {
70- value : string ;
71- label : string ;
72- } > ,
73- metaAction : ActionMeta < {
74- value : string ;
75- label : string ;
76- } >
77- ) => {
78- // eslint-disable-next-line
79- const value = newValue ! . value ;
80- const label = metaAction . name ;
81-
82- const newIndentOptions = indentOptions . map ( ( option ) => {
83- if ( option . label === label ) {
84- return { value, label } ;
85- }
86- return option ;
87- } ) ;
88-
89- setIndentOptions ( newIndentOptions ) ;
90-
91- chrome . storage . local . set ( { scrapboxIndentOption : newIndentOptions } ) ;
92-
93- chrome . tabs . query ( { active : true , currentWindow : true } , ( tabs ) => {
94- tabs . forEach ( ( tab ) => {
95- if ( tab . url === undefined || tab . id === undefined ) return ;
96- const url = new URL ( tab . url ) ;
97- if ( url . hostname === 'scrapbox.io' ) {
98- chrome . tabs . sendMessage ( tab . id , 'scrapbox_list_maker' ) ;
99- }
100- } ) ;
101- } ) ;
102- } ;
103-
10472 return (
10573 < MainContainer >
106- < TitleWrapper >
107- < Title > Select Favorite List Maker</ Title >
108- < SwitchLabel >
109- < Switch
110- checked = { indentLining }
111- onChange = { handleIndentLiningChange }
112- onColor = "#00b428"
113- boxShadow = "0px 1px 5px rgba(0, 0, 0, 0.6)"
114- height = { 16 }
115- width = { 30 }
116- handleDiameter = { 18 }
117- checkedIcon = { false }
118- uncheckedIcon = { false }
119- />
120- < Spacer width = { 6 } />
121- < span > Indent Visible</ span >
122- </ SwitchLabel >
123- </ TitleWrapper >
124- < IndentContainer >
125- { indentOptions . map ( ( indentOption ) => {
126- const spaceNum = + indentOption . label . replace ( / [ ^ 0 - 9 ] / g, '' ) - 1 ;
127-
128- return (
129- < >
130- < IndentRow spaceNum = { spaceNum } >
131- < Select
132- value = { {
133- value : indentOption . value ,
134- label : indentOption . value ,
135- } }
136- onChange = { handleOnChange }
137- key = { indentOption . label }
138- name = { indentOption . label }
139- options = { options }
140- > </ Select >
141- < Label > { indentOption . label } </ Label >
142- </ IndentRow >
143- </ >
144- ) ;
145- } ) }
146- </ IndentContainer >
147- < Demonstration hasLine = { indentLining } indentOptions = { indentOptions } />
74+ < MakerConsole
75+ indentOptions = { indentOptions }
76+ setIndentOptions = { setIndentOptions }
77+ indentLining = { indentLining }
78+ handleIndentLiningChange = { handleIndentLiningChange }
79+ setIndentLiningColor = { setIndentLiningColor }
80+ />
81+ < Demonstration
82+ hasLine = { indentLining }
83+ indentOptions = { indentOptions }
84+ indentLiningColor = { indentLiningColor }
85+ />
14886 </ MainContainer >
14987 ) ;
15088} ;
@@ -154,41 +92,3 @@ const MainContainer = styled.div`
15492 padding: 4px;
15593 padding-bottom: 8px;
15694` ;
157-
158- const Spacer = styled . div < { width : number } > `
159- width: ${ ( props ) => props . width } px;
160- ` ;
161-
162- const TitleWrapper = styled . div `
163- display: flex;
164- align-items: center;
165- ` ;
166-
167- const Title = styled . div `
168- font-size: 16px;
169- text-align: left;
170- margin: 10px 12px;
171- ` ;
172-
173- const SwitchLabel = styled . label `
174- margin-left: 8px;
175- display: flex;
176- align-items: center;
177- ` ;
178-
179- const Label = styled . div `
180- font-size: 14px;
181- margin-left: 12px;
182- ` ;
183-
184- const IndentContainer = styled . div `
185- margin: 0px 10px;
186- ` ;
187-
188- const IndentRow = styled . div < { spaceNum : number } > `
189- margin-left: ${ ( props ) => `${ props . spaceNum * 30 } px` } ;
190- margin-top: 4px;
191- margin-bottom: 4px;
192- display: flex;
193- align-items: center;
194- ` ;
0 commit comments