-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Fixes exports and example build after version upgrades (#10)
* Fixes issues with mjs in exports * Minify the bundle * Updates documentation and example story * Adds a static pages deploy action * Removes extra build, use newer pnpm action version * Adds an example of a button on an individual story
Showing
12 changed files
with
326 additions
and
58 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: Deploy static content to Pages | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
workflow_dispatch: | ||
|
||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Pages | ||
uses: actions/configure-pages@v5 | ||
|
||
- uses: pnpm/action-setup@v4 | ||
with: | ||
version: 9.4.0 | ||
run_install: true | ||
|
||
- name: Build Ladle static content | ||
run: pnpm ladle build | ||
env: | ||
BASE_URL: ${{ github.event.repository.name }} | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: "build" | ||
|
||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from "react" | ||
|
||
export const Context = React.createContext({ | ||
message: ( | ||
<p> | ||
If you can see this message, it means that the addon is not receiving data | ||
from the context provider in the CustomGlobalProvider component. Dang. | ||
</p> | ||
), | ||
}) | ||
|
||
export const contextMessage = ( | ||
<> | ||
<p> | ||
This message being displayed shows that the addon button is able to | ||
receive data from a context provider. Yay! | ||
</p> | ||
<p> | ||
This message is populated from a context provided in the{" "} | ||
<code>CustomGlobalProvider</code> component. If you want to know more | ||
about how it works, check out the{" "} | ||
<a href="https://github.com/hiddenist/ladle-inject-custom-addons/blob/main/.ladle/components.tsx"> | ||
components.tsx | ||
</a>{" "} | ||
source code on GitHub. | ||
</p> | ||
</> | ||
) |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from "react" | ||
|
||
const PlusOne = () => { | ||
return <div className="plus-one">+1</div> | ||
} | ||
|
||
export const usePlusOneAnimated = () => { | ||
const [elements, setElements] = React.useState<React.ReactNode[]>([]) | ||
|
||
const addPlusOne = React.useCallback(() => { | ||
const element = <PlusOne key={Date.now()} /> | ||
setElements((elems) => [...elems, element]) | ||
setTimeout(() => { | ||
setElements((elems) => elems.filter((e) => e !== element)) | ||
}, 1000) | ||
}, []) | ||
|
||
return { | ||
addPlusOne, | ||
elements, | ||
} | ||
} |
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
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,8 +1,84 @@ | ||
import type { Story } from "@ladle/react"; | ||
import React from "react" | ||
import type { Story } from "@ladle/react" | ||
import { PlusCircle } from "react-feather" | ||
import { AddonButton } from "ladle-inject-custom-addons" | ||
import { usePlusOneAnimated } from "./components/PlusOneAnimated" | ||
|
||
export const Simple: Story = () => ( | ||
<ul> | ||
<li>Item 1</li> | ||
<li>Item 2</li> | ||
</ul> | ||
export const Home: Story = () => ( | ||
<div className="home"> | ||
<h1>ladle-inject-custom-addons</h1> | ||
<div className="github-badges"> | ||
<a href="https://npmjs.com/package/ladle-inject-custom-addons"> | ||
<img | ||
src="https://img.shields.io/npm/v/ladle-inject-custom-addons.svg" | ||
alt="npm package" | ||
/> | ||
</a> | ||
<a href="https://github.com/hiddenist/ladle-inject-custom-addons/actions/workflows/ci.yml"> | ||
<img | ||
src="https://github.com/hiddenist/ladle-inject-custom-addons/actions/workflows/ci.yml/badge.svg?branch=main" | ||
alt="build status" | ||
/> | ||
</a> | ||
</div> | ||
<img | ||
width="686" | ||
alt="A screenshot of the Ladle addon bar, with a dialog box displaying text: 'ladle-inject-custom-addons' Add your own components in the Ladle addon panel! ✨🐙✨" | ||
src="https://github.com/hiddenist/ladle-inject-custom-addons/assets/563879/235b9c68-a7e5-40f3-b2cc-838f7c608b19" | ||
/> | ||
<p> | ||
This is a working example of the <code>ladle-inject-custom-addons</code>{" "} | ||
package. Check out the buttons at the bottom of the screen to see it in | ||
action. | ||
</p> | ||
<p> | ||
Learn more at the{" "} | ||
<a href="https://github.com/hiddenist/ladle-inject-custom-addons"> | ||
hiddenist/ladle-inject-custom-addons | ||
</a>{" "} | ||
GitHub repository! | ||
</p> | ||
</div> | ||
) | ||
|
||
export const StoryWithAddon: Story = () => { | ||
const [clickCount, setClickCount] = React.useState(0) | ||
|
||
const { elements, addPlusOne } = usePlusOneAnimated() | ||
|
||
return ( | ||
<div> | ||
<h1>This story has its own addon button</h1> | ||
<p> | ||
In addition to creating addon buttons in the global context, you can | ||
also create addon buttons that only show up for specific stories! | ||
</p> | ||
<p> | ||
<h2> | ||
You have clicked the button {clickCount} time{clickCount != 1 && "s"} | ||
</h2> | ||
</p> | ||
<p> | ||
Curious how it's done? Find the source code button and take a look at | ||
the code for this story! | ||
</p> | ||
|
||
<AddonButton | ||
icon={ | ||
<> | ||
<PlusCircle /> | ||
{elements} | ||
</> | ||
} | ||
label="Count clicks" | ||
tooltip="Increment the click count for this story" | ||
position={0} | ||
badge={clickCount < 10 ? clickCount : "9+"} | ||
onClick={() => { | ||
addPlusOne() | ||
setClickCount((c) => c + 1) | ||
}} | ||
/> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.