-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from RodrigoHamuy/ladle-tweaks
add description to stories
- Loading branch information
Showing
4 changed files
with
104 additions
and
9 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,52 @@ | ||
import { GlobalProvider } from "@ladle/react"; | ||
import './style.css'; | ||
import React, { memo, useCallback, useEffect, useState } from "react"; | ||
import { createPortal } from "react-dom"; | ||
import burgerSvg from './burger.svg'; | ||
|
||
// @ts-ignore | ||
export const Provider: GlobalProvider = ({ children }) => <>{children}</> | ||
export const Provider: GlobalProvider = ({ children }) => { | ||
const [header] = useState(() => document.createElement('div')); | ||
|
||
const toggle = useCallback(() => { | ||
if (!header.parentElement) return; | ||
header.parentElement.classList.toggle('hide') | ||
}, []) | ||
|
||
useEffect(() => { | ||
const container = document.querySelector('.ladle-aside'); | ||
if (!container) return; | ||
container.prepend(header); | ||
container.classList.add('hide'); | ||
return () => { | ||
header.remove(); | ||
} | ||
|
||
}, []) | ||
return <> | ||
{createPortal(<Header toggle={toggle} />, header)} | ||
{children} | ||
</> | ||
} | ||
|
||
interface HeaderProps { | ||
toggle: () => void; | ||
} | ||
|
||
const Header = memo<HeaderProps>(({ toggle }) => { | ||
return <> | ||
<button className="story-menu-btn" onClick={toggle}><img src={burgerSvg} alt="toggle menu" /></button> | ||
<h1><img src="favicon.svg" style={{ width: '1rem' }} /> react-three-map</h1> | ||
<div style={{ paddingBottom: 15 }} className="story-header"> | ||
<p>R3F inside Mapbox & Maplibre</p> | ||
<div style={{ display: 'inline-grid', gap: 10, gridTemplateColumns: 'repeat(2,auto' }}> | ||
<a href="https://github.com/RodrigoHamuy/react-three-map" target="_blank" rel="noopener noreferrer"> | ||
<img src="https://img.shields.io/static/v1?&message=github&style=flat&colorA=000000&colorB=000000&label=&logo=github&logoColor=ffffff" alt="react-three-map repository" /> | ||
</a> | ||
<a href="https://www.npmjs.com/package/react-three-map" target="_blank" rel="noopener noreferrer"> | ||
<img src={`https://img.shields.io/npm/v/react-three-map?style=flat&colorA=000000&colorB=000000&logo=npm`} alt="react-three-map NPM package" /> | ||
</a> | ||
</div> | ||
</div> | ||
</> | ||
}) | ||
Header.displayName = 'Header'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,63 @@ | ||
.ladle-main{ | ||
.ladle-main { | ||
padding: 0; | ||
} | ||
|
||
.ladle-aside { | ||
order: -1; | ||
padding: 1em 1.5em; | ||
} | ||
|
||
header.ladle-addons { | ||
max-width: 18em | ||
} | ||
header.ladle-addons ul{ | ||
|
||
header.ladle-addons ul { | ||
flex-wrap: wrap; | ||
} | ||
header.ladle-addons li{ | ||
|
||
header.ladle-addons li { | ||
margin: 0.35em; | ||
} | ||
|
||
header.ladle-addons li:nth-of-type(4) { | ||
display: none; | ||
} | ||
|
||
.story-menu-btn { | ||
border: none; | ||
background: none; | ||
position: fixed; | ||
right: 1rem; | ||
} | ||
|
||
.story-menu-btn img { | ||
width: 2rem; | ||
height: 2rem; | ||
} | ||
|
||
@media (max-width: 767px) { | ||
.ladle-aside h1 { | ||
margin: 0; | ||
} | ||
|
||
.ladle-aside { | ||
position: fixed; | ||
left: 0; | ||
right: 0; | ||
top: 0; | ||
} | ||
|
||
.hide.ladle-aside>*:not(:first-child) { | ||
display: none; | ||
} | ||
|
||
.hide .story-header { | ||
display: none; | ||
} | ||
} | ||
|
||
@media (min-width: 768px) { | ||
.story-menu-btn { | ||
display: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters