mirror of
https://github.com/chinchang/web-maker.git
synced 2025-05-07 19:15:24 +02:00
Refactor settings. Add switches and tabs. fixes #339
This commit is contained in:
parent
ec4ce2be29
commit
f2a96b3ec2
@ -1,6 +1,7 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
import { editorThemes } from '../editorThemes';
|
import { editorThemes } from '../editorThemes';
|
||||||
import Switch from './Switch';
|
import Switch from './Switch';
|
||||||
|
import Tabs, { TabPanel } from './Tabs';
|
||||||
|
|
||||||
function CheckboxSetting({
|
function CheckboxSetting({
|
||||||
title,
|
title,
|
||||||
@ -40,7 +41,8 @@ export default class Settings extends Component {
|
|||||||
<div>
|
<div>
|
||||||
<h1>Settings</h1>
|
<h1>Settings</h1>
|
||||||
|
|
||||||
<h3>Indentation</h3>
|
<Tabs>
|
||||||
|
<TabPanel label="Indentation">
|
||||||
<div
|
<div
|
||||||
class="line"
|
class="line"
|
||||||
title="I know this is tough, but you have to decide one!"
|
title="I know this is tough, but you have to decide one!"
|
||||||
@ -91,11 +93,9 @@ export default class Settings extends Component {
|
|||||||
<option>7</option>
|
<option>7</option>
|
||||||
</datalist>
|
</datalist>
|
||||||
</label>
|
</label>
|
||||||
|
</TabPanel>
|
||||||
<hr />
|
<TabPanel label="Editor">
|
||||||
|
<div class="fle block--mobile">
|
||||||
<h3>Editor</h3>
|
|
||||||
<div class="flex block--mobile">
|
|
||||||
<div>
|
<div>
|
||||||
<label class="line">Default Preprocessors</label>
|
<label class="line">Default Preprocessors</label>
|
||||||
<div class="flex line">
|
<div class="flex line">
|
||||||
@ -210,7 +210,7 @@ export default class Settings extends Component {
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-grow ml-2 ml-0--mobile">
|
<div class="flex-grow">
|
||||||
<CheckboxSetting
|
<CheckboxSetting
|
||||||
name="lineWrap"
|
name="lineWrap"
|
||||||
title="Toggle wrapping of long sentences onto new line"
|
title="Toggle wrapping of long sentences onto new line"
|
||||||
@ -277,10 +277,8 @@ export default class Settings extends Component {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</TabPanel>
|
||||||
<hr />
|
<TabPanel label="Fun">
|
||||||
|
|
||||||
<h3>Fun</h3>
|
|
||||||
<p>
|
<p>
|
||||||
<CheckboxSetting
|
<CheckboxSetting
|
||||||
title="Enjoy wonderful particle blasts while you type"
|
title="Enjoy wonderful particle blasts while you type"
|
||||||
@ -298,10 +296,8 @@ export default class Settings extends Component {
|
|||||||
onChange={this.updateSetting.bind(this)}
|
onChange={this.updateSetting.bind(this)}
|
||||||
/>
|
/>
|
||||||
</p>
|
</p>
|
||||||
|
</TabPanel>
|
||||||
<hr />
|
<TabPanel label="Advanced">
|
||||||
|
|
||||||
<h3>Advanced</h3>
|
|
||||||
<p>
|
<p>
|
||||||
<label
|
<label
|
||||||
class="line"
|
class="line"
|
||||||
@ -338,6 +334,8 @@ export default class Settings extends Component {
|
|||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
|
</TabPanel>
|
||||||
|
</Tabs>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
16
src/components/Switch.jsx
Normal file
16
src/components/Switch.jsx
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { h, Component } from 'preact';
|
||||||
|
|
||||||
|
export default class Switch extends Component {
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<label class="check-switch">
|
||||||
|
{this.props.children}
|
||||||
|
<input role="switch" type="checkbox" checked={this.props.checked} />
|
||||||
|
<span aria-hidden="true" class="check-switch__toggle" />
|
||||||
|
<span aria-hidden="true" class="check-switch__status">
|
||||||
|
{this.props.checked ? 'on' : 'off'}
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
79
src/components/Tabs.jsx
Normal file
79
src/components/Tabs.jsx
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
import { h, Component } from 'preact';
|
||||||
|
|
||||||
|
function hyphenate(text) {
|
||||||
|
return text.replace(/\s/g, '-');
|
||||||
|
}
|
||||||
|
const ID_PREFIX = 'tab-panel-';
|
||||||
|
export function TabPanel({ label }) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
class="tabs__tabpanel"
|
||||||
|
role="tabpanel"
|
||||||
|
id={`${ID_PREFIX}${hyphenate(label)}`}
|
||||||
|
>
|
||||||
|
{this.props.children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function Tab({ label, isSelected, onKeyUp, onClick }) {
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
class={`tabs__tab ${isSelected ? 'tabs__tab--selected' : ''}`}
|
||||||
|
role="tab"
|
||||||
|
tabindex={isSelected ? null : -1}
|
||||||
|
aria-selected={isSelected}
|
||||||
|
aria-controls={`${ID_PREFIX}${hyphenate(label)}`}
|
||||||
|
onKeyUp={onKeyUp}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
export default class Tabs extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
selectedTab: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
isSelected(index) {
|
||||||
|
return this.state.selectedTab === index;
|
||||||
|
}
|
||||||
|
keyUpHandler(e) {
|
||||||
|
let { selectedTab } = this.state;
|
||||||
|
if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
|
||||||
|
selectedTab--;
|
||||||
|
selectedTab = selectedTab < 0 ? this.props.length - 1 : selectedTab;
|
||||||
|
this.setState({ selectedTab: selectedTab });
|
||||||
|
e.preventDefault();
|
||||||
|
} else if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
|
||||||
|
selectedTab++;
|
||||||
|
selectedTab %= this.props.children.length;
|
||||||
|
this.setState({ selectedTab: selectedTab });
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
const tabs = this.props.children;
|
||||||
|
return (
|
||||||
|
<div class="tabs">
|
||||||
|
<div class="tabs__tablist" role="tablist">
|
||||||
|
{tabs.map((child, index) => (
|
||||||
|
<Tab
|
||||||
|
isSelected={this.isSelected(index)}
|
||||||
|
label={child.props.label}
|
||||||
|
onKeyUp={this.keyUpHandler.bind(this)}
|
||||||
|
onClick={() => this.setState({ selectedTab: index })}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<div class="tabs__tabpanel-wrap">
|
||||||
|
{tabs.map(
|
||||||
|
(child, index) => (this.state.selectedTab === index ? child : null)
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -976,10 +976,9 @@ body > #demo-frame {
|
|||||||
|
|
||||||
/* Make settings modal smaller */
|
/* Make settings modal smaller */
|
||||||
|
|
||||||
@media screen and (min-width: 600px) {
|
@media screen and (min-width: 850px) {
|
||||||
.modal--settings {
|
.modal--settings > .modal__content {
|
||||||
/* width: 600px; */
|
width: 850px;
|
||||||
/* margin-lef.t: -300px; */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1891,6 +1890,29 @@ while the theme CSS file is loading */
|
|||||||
padding: 5px;
|
padding: 5px;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
.tabs {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
.tabs__tablist {
|
||||||
|
margin-right: 40px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
.tabs__tab {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
background: transparent;
|
||||||
|
border: 0;
|
||||||
|
text-align: left;
|
||||||
|
width: 100%;
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
.tabs__tab--selected {
|
||||||
|
background-color: rgba(0, 0, 0, 0.3);
|
||||||
|
}
|
||||||
|
.tabs__tabpanel-wrap {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 600px) {
|
@media screen and (max-width: 600px) {
|
||||||
body {
|
body {
|
||||||
font-size: 70%;
|
font-size: 70%;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user