Skip to content

Commit

Permalink
Document no-css version.
Browse files Browse the repository at this point in the history
  • Loading branch information
molefrog committed Mar 4, 2024
1 parent 7645ca4 commit 4b51a01
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## Realistic `<Spoiler />` component for React

Inspired by [Telegram spoilers](https://telegram.org/blog/reactions-spoilers-translations#spoilers), **spoiled** renders an animated particle cloud covering text, inline
or block elements, keeping them hidden until revealed.
Inspired by [Telegram spoilers](https://telegram.org/blog/reactions-spoilers-translations#spoilers),
**spoiled** renders an animated particle cloud covering text, inline or block elements, keeping them
hidden until revealed.

- Uses **[CSS Painting API](https://caniuse.com/css-paint-api) (Houdini)** to achive realistic
rendering for inline elements. Comes with a static image **fallback**;
Expand All @@ -25,9 +26,6 @@ Wrap your text in a spoiler, so the plot twists stay hidden:
```jsx
import { Spoiler } from "spoiled";

// content transitions
import "spoiled/style.css";

// Reveals on hover
<Spoiler>
Hogwarts is a high-tech <b>startup incubator</b>
Expand All @@ -39,6 +37,7 @@ By default, the spoiler:
- reveals on hover (uncontrolled)
- uses system color scheme
- wraps the content in a `span` element
- injects a small CSS for content transitions (please read below on how to opt out)

All standard props are proxied to the underlying `span` element. You can also use `tagName` prop to
change the tag:
Expand Down Expand Up @@ -128,6 +127,19 @@ Since it can be inaccurate, use `mimicWords` setting to disable it:
<Spoiler mimicWords={false}>This will be rendered as a solid line of text</Spoiler>
```

### Styling

Spoiled will on-demand inject a small `<style>` tag into the document with a CSS needed to animate
hide and reveal transitions. You can use an unstyled version instead and load these styles
differently.

```jsx
import { Spoiler } from "spoiled/no-css";

// If you're using Vite or similar bundler, these styles will be written to the final CSS bundle
import "spoiled/style.css";
```

## Disclaimer

As of 2024, [CSS Houdini API](https://caniuse.com/css-paint-api) is supported by the 70% of the
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "spoiled",
"description": "Realistic animated <Spoiler /> component for React",
"version": "0.2.0",
"version": "0.2.1",
"type": "module",
"license": "Unlicense",
"main": "esm/index.js",
Expand All @@ -10,7 +10,7 @@
"types": "./esm/index.d.ts",
"default": "./esm/index.js"
},
"./unstyled": {
"./no-css": {
"types": "./esm/index_unstyled.d.ts",
"default": "./esm/index_unstyled.js"
},
Expand All @@ -21,7 +21,7 @@
".": [
"esm/index.d.ts"
],
"unstyled": [
"no-css": [
"esm/index_unstyled.d.ts"
]
}
Expand Down

0 comments on commit 4b51a01

Please sign in to comment.