11import React , { useEffect , useState } from 'react' ;
22import Select , { ActionMeta , SingleValue } from 'react-select' ;
3+ import Switch from 'react-switch' ;
34import styled from 'styled-components' ;
45
56const options = [
@@ -25,6 +26,7 @@ export const Console: React.FC<Props> = () => {
2526 label : string ;
2627 } [ ]
2728 > ( initialState ) ;
29+ const [ indentColoring , setIndentColoring ] = useState < boolean > ( false ) ;
2830
2931 useEffect ( ( ) => {
3032 chrome . storage . local . get ( 'scrapboxIndentOption' , ( result ) => {
@@ -37,8 +39,34 @@ export const Console: React.FC<Props> = () => {
3739 setIndentOptions ( scrapboxIndentOption ) ;
3840 }
3941 } ) ;
42+
43+ chrome . storage . local . get ( 'scrapboxIndentColoring' , ( result ) => {
44+ const scrapboxIndentColoring = result . scrapboxIndentColoring ;
45+
46+ if ( ! scrapboxIndentColoring ) {
47+ chrome . storage . local . set ( { scrapboxIndentColoring : false } ) ;
48+ setIndentColoring ( false ) ;
49+ } else {
50+ setIndentColoring ( scrapboxIndentColoring ) ;
51+ }
52+ } ) ;
4053 } , [ ] ) ;
4154
55+ const handleIndentColoringChange = ( checked : boolean ) => {
56+ chrome . storage . local . set ( { scrapboxIndentColoring : checked } ) ;
57+ setIndentColoring ( checked ) ;
58+
59+ chrome . tabs . query ( { active : true , currentWindow : true } , ( tabs ) => {
60+ tabs . forEach ( ( tab ) => {
61+ if ( tab . url === undefined || tab . id === undefined ) return ;
62+ const url = new URL ( tab . url ) ;
63+ if ( url . hostname === 'scrapbox.io' ) {
64+ chrome . tabs . sendMessage ( tab . id , 'scrapbox_indent_coloring' ) ;
65+ }
66+ } ) ;
67+ } ) ;
68+ } ;
69+
4270 const handleOnChange = (
4371 newValue : SingleValue < {
4472 value : string ;
@@ -67,7 +95,6 @@ export const Console: React.FC<Props> = () => {
6795 chrome . tabs . query ( { active : true , currentWindow : true } , ( tabs ) => {
6896 tabs . forEach ( ( tab ) => {
6997 if ( tab . url === undefined || tab . id === undefined ) return ;
70-
7198 const url = new URL ( tab . url ) ;
7299 if ( url . hostname === 'scrapbox.io' ) {
73100 chrome . tabs . sendMessage ( tab . id , 'scrapbox_list_maker' ) ;
@@ -78,7 +105,24 @@ export const Console: React.FC<Props> = () => {
78105
79106 return (
80107 < MainContainer >
81- < Title > Select Favorite List Maker</ Title >
108+ < TitleWrapper >
109+ < Title > Select Favorite List Maker</ Title >
110+ < SwitchLabel >
111+ < Switch
112+ checked = { indentColoring }
113+ onChange = { handleIndentColoringChange }
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 Line</ span >
124+ </ SwitchLabel >
125+ </ TitleWrapper >
82126 < IndentContainer >
83127 { indentOptions . map ( ( indentOption ) => {
84128 const spaceNum = + indentOption . label . replace ( / [ ^ 0 - 9 ] / g, '' ) - 1 ;
@@ -102,7 +146,6 @@ export const Console: React.FC<Props> = () => {
102146 ) ;
103147 } ) }
104148 </ IndentContainer >
105-
106149 < DemonstrationContainer >
107150 < Demonstration >
108151 < Title > Demonstration</ Title >
@@ -134,12 +177,27 @@ const MainContainer = styled.div`
134177 padding-bottom: 8px;
135178` ;
136179
180+ const Spacer = styled . div < { width : number } > `
181+ width: ${ ( props ) => props . width } px;
182+ ` ;
183+
184+ const TitleWrapper = styled . div `
185+ display: flex;
186+ align-items: center;
187+ ` ;
188+
137189const Title = styled . div `
138190 font-size: 16px;
139191 text-align: left;
140192 margin: 12px 10px;
141193` ;
142194
195+ const SwitchLabel = styled . label `
196+ margin-left: 8px;
197+ display: flex;
198+ align-items: center;
199+ ` ;
200+
143201const Label = styled . div `
144202 font-size: 14px;
145203 margin-left: 12px;
0 commit comments