Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset focus button #27

Merged
merged 4 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/webapp/icons/FocusIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
aria-hidden="true"
>
<path d="M4.25 2A2.25 2.25 0 002 4.25v2a.75.75 0 001.5 0v-2a.75.75 0 01.75-.75h2a.75.75 0 000-1.5h-2zM13.75 2a.75.75 0 000 1.5h2a.75.75 0 01.75.75v2a.75.75 0 001.5 0v-2A2.25 2.25 0 0015.75 2h-2zM3.5 13.75a.75.75 0 00-1.5 0v2A2.25 2.25 0 004.25 18h2a.75.75 0 000-1.5h-2a.75.75 0 01-.75-.75v-2zM18 13.75a.75.75 0 00-1.5 0v2a.75.75 0 01-.75.75h-2a.75.75 0 000 1.5h2A2.25 2.25 0 0018 15.75v-2zM7 10a3 3 0 116 0 3 3 0 01-6 0z" />
</svg>;

export function FocusIcon() {
return (
<svg
width="20"
height="20"
aria-hidden="true"
scale="1"
type="outlined"
stroke="#212121"
fill="#212121"
viewBox="0 0 20 20"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M4.25 2A2.25 2.25 0 002 4.25v2a.75.75 0 001.5 0v-2a.75.75 0 01.75-.75h2a.75.75 0 000-1.5h-2zM13.75 2a.75.75 0 000 1.5h2a.75.75 0 01.75.75v2a.75.75 0 001.5 0v-2A2.25 2.25 0 0015.75 2h-2zM3.5 13.75a.75.75 0 00-1.5 0v2A2.25 2.25 0 004.25 18h2a.75.75 0 000-1.5h-2a.75.75 0 01-.75-.75v-2zM18 13.75a.75.75 0 00-1.5 0v2a.75.75 0 01-.75.75h-2a.75.75 0 000 1.5h2A2.25 2.25 0 0018 15.75v-2zM7 10a3 3 0 116 0 3 3 0 01-6 0z" />
</svg>
);
}
26 changes: 25 additions & 1 deletion src/webapp/layout/story/Story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ export const StoryComponent = observer(({ story }: { story: Story }) => {
<Prewview
style={{ background: darkMode.isDarkMode ? "#000" : "#fff" }}
>
<ResetPoint tabIndex={-1} id={`reset-${sectionId}`} />
{story.center ? (
<Center style={{ height: "100%" }}>{renderdStory}</Center>
) : (
<div>{renderdStory}</div>
)}
</Prewview>
<ControlsWrapper>
<Controls controls={controls} darkMode={darkMode} />
<Controls
sectionId={sectionId}
controls={controls}
darkMode={darkMode}
/>
</ControlsWrapper>
</Configurator>
{story.codeTemplate && (
Expand All @@ -69,6 +74,24 @@ export const StoryComponent = observer(({ story }: { story: Story }) => {
);
});

const ResetPoint = styled("button")`
position: absolute;
top: 0;
left: 0;
pointer-events: none;
outline: 0;
margin: 0;
padding: 0;
width: 24px;
height: 24px;
border: none;
background-color: transparent;
border-radius: 6px;
&:focus {
outline: 2px solid #238be6;
}
`;

const StoryTitle = styled(Title)`
margin-top: 24px !important;
margin-bottom: 12px !important;
Expand All @@ -91,6 +114,7 @@ const Configurator = styled("div")({
});

const Prewview = styled.div`
position: relative;
flex: 1;
padding: 16px;
background: rgb(255, 255, 255);
Expand Down
71 changes: 47 additions & 24 deletions src/webapp/layout/story/control/Controls.tsx
Original file line number Diff line number Diff line change
@@ -1,47 +1,64 @@
import styled from '@emotion/styled';
import { Switch, Text, Button } from '@mantine/core';
import { action } from 'mobx';
import { observer } from 'mobx-react-lite';
import { Fragment } from 'react';
import { ControlTitle } from './atoms';
import { BooleanControl } from './BooleanControl';
import { ColorControl } from './ColorControl';
import { SegmentControl } from './SegmentControl';
import { TextControl } from './TextControl';
import { NumberControl } from './NumberControl';
import { Control } from './useControl';
import { DarkMode } from './useIsDarkMode';
import styled from "@emotion/styled";
import { Switch, Text, Button, ActionIcon, Tooltip } from "@mantine/core";
import { action } from "mobx";
import { observer } from "mobx-react-lite";
import { Fragment } from "react";
import { ControlTitle } from "./atoms";
import { BooleanControl } from "./BooleanControl";
import { ColorControl } from "./ColorControl";
import { SegmentControl } from "./SegmentControl";
import { TextControl } from "./TextControl";
import { NumberControl } from "./NumberControl";
import { Control } from "./useControl";
import { DarkMode } from "./useIsDarkMode";
import { FocusIcon } from "../../../icons/FocusIcon";

interface Props {
controls: Control;
darkMode: DarkMode;
sectionId: string;
}

export const Controls = observer(({ controls, darkMode }: Props) => {
export const Controls = observer(({ controls, darkMode, sectionId }: Props) => {
return (
<>
<HelpActions>
<Tooltip withArrow arrowPosition="center" label="Reset focus">
<ActionIcon
onClick={() => {
const resetEl = document.getElementById(`reset-${sectionId}`);
if (resetEl) {
resetEl.focus();
}
}}
size="lg"
>
<FocusIcon />
</ActionIcon>
</Tooltip>
</HelpActions>
<Switch
label="Darkmode"
checked={darkMode.isDarkMode}
onChange={action(event =>
onChange={action((event) =>
darkMode.setIsDarkMode(event.currentTarget.checked)
)}
/>
<ControlSpace />
{Object.entries(controls.state).map(([name, control]) => {
switch (control.type) {
case 'color':
case "color":
return (
<Fragment key={name}>
<ControlTitle order={6}>{control.displayName}</ControlTitle>
<ColorControl control={control} />
<ControlSpace />
</Fragment>
);
case 'boolean':
case "boolean":
return (
<Fragment key={name}>
<Text size="xs" color="gray" style={{ marginBottom: '8px' }}>
<Text size="xs" color="gray" style={{ marginBottom: "8px" }}>
{control.description}
</Text>
<BooleanControl
Expand All @@ -52,36 +69,36 @@ export const Controls = observer(({ controls, darkMode }: Props) => {
<ControlSpace />
</Fragment>
);
case 'text':
case "text":
return (
<Fragment key={name}>
<ControlTitle order={6}>{control.displayName}</ControlTitle>
<Text size="xs" color="gray" style={{ marginBottom: '8px' }}>
<Text size="xs" color="gray" style={{ marginBottom: "8px" }}>
{control.description}
</Text>
<TextControl control={control} />
<ControlSpace />
</Fragment>
);
case 'number':
case "number":
return (
<Fragment key={name}>
<ControlTitle order={6}>{control.displayName}</ControlTitle>
<Text size="xs" color="gray" style={{ marginBottom: '8px' }}>
<Text size="xs" color="gray" style={{ marginBottom: "8px" }}>
{control.description}
</Text>
<NumberControl control={control} />
<ControlSpace />
</Fragment>
);
case 'segment':
case "segment":
return (
<Fragment key={name}>
<SegmentControl control={control} name={control.displayName!} />
<ControlSpace />
</Fragment>
);
case 'button':
case "button":
return (
<Fragment key={name}>
<Button children={control.name} onClick={control.value} />
Expand All @@ -96,6 +113,12 @@ export const Controls = observer(({ controls, darkMode }: Props) => {
);
});

const HelpActions = styled("div")`
margin-top: -6px;
margin-bottom: 16px;
padding-bottom: 6px;
`;

const ControlSpace = styled.div`
margin-bottom: 12px;
`;