Skip to content

Commit

Permalink
demo: remove dynamic buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuel Suriano committed Oct 15, 2022
1 parent 868c93f commit c9d4121
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 38 deletions.
33 changes: 4 additions & 29 deletions packages/demo/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { useState } from 'react';
import { ScrollingProvider, Section } from 'react-scroll-section';
import ModeToggle, { MenuKind } from './ModeToggle';
import ModeToggle, { Mode } from './ModeToggle';
import { DynamicMenu, StaticMenu } from './Menu';
import { Footer, Menu, SectionContainer } from './Builders';
import logo from './logo.svg';

function App() {
const [menu, setMenu] = useState<MenuKind>('dynamic');
const [sections, setSections] = useState(['s1']);
const [mode, setMode] = useState<Mode>('dynamic');

return (
<ScrollingProvider>
<Menu>{menu === 'static' ? <StaticMenu /> : <DynamicMenu />}</Menu>
<Menu>{mode === 'static' ? <StaticMenu /> : <DynamicMenu />}</Menu>

<Section id="home">
<SectionContainer>
Expand Down Expand Up @@ -46,32 +45,8 @@ function App() {
</SectionContainer>
</Section>

{sections.map((name) => (
<Section id={name} key={name}>
<SectionContainer>
<span role="img" aria-label="letter">
{name}
</span>
<button
onClick={() => {
setSections((prev) => [...prev, 's' + (prev.length + 1)]);
}}
>
Add
</button>
<button
onClick={() => {
setSections((prev) => prev.filter((s) => s !== name));
}}
>
Remove
</button>
</SectionContainer>
</Section>
))}

<Footer>
<ModeToggle menu={menu} onChange={setMenu} />
<ModeToggle mode={mode} onChange={setMode} />
<a href="https://www.netlify.com">
<img
src="https://www.netlify.com/img/global/badges/netlify-color-bg.svg"
Expand Down
18 changes: 9 additions & 9 deletions packages/demo/src/ModeToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import styled from 'styled-components';
import Toggle from 'react-toggle';

export type MenuKind = 'static' | 'dynamic';
export type Mode = 'static' | 'dynamic';

type Props = {
menu: MenuKind;
onChange: (menu: MenuKind) => void;
mode: Mode;
onChange: (mode: Mode) => void;
};

const ModeToggle = ({ menu, onChange }: Props) => (
const ModeToggle = ({ mode, onChange }: Props) => (
<Container>
<Toggle
id="menu-type"
defaultChecked={menu === 'static'}
id="mode-type"
defaultChecked={mode === 'dynamic'}
onChange={({ currentTarget }) =>
onChange(currentTarget.checked ? 'static' : 'dynamic')
onChange(currentTarget.checked ? 'dynamic' : 'static')
}
/>
<label htmlFor="menu-type" style={{ marginLeft: '10px' }}>
Menu: <b>{menu}</b>
<label htmlFor="mode-type" style={{ marginLeft: '10px' }}>
Mode: <b>{mode}</b>
</label>
</Container>
);
Expand Down

0 comments on commit c9d4121

Please sign in to comment.