Skip to content

Commit 250ffa6

Browse files
committed
Add initial implementation
1 parent 05f2a98 commit 250ffa6

File tree

8 files changed

+564
-146
lines changed

8 files changed

+564
-146
lines changed

.github/workflows/deploy.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- main
6+
permissions:
7+
contents: read
8+
jobs:
9+
deploy:
10+
name: Demo Deploy
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
steps:
15+
- name: Checkout the repository
16+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
17+
with:
18+
persist-credentials: false
19+
- name: Install pnpm
20+
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
21+
with:
22+
version: 10
23+
- name: Install Node.js
24+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
25+
with:
26+
node-version: 24
27+
cache: pnpm
28+
- name: Install dependencies
29+
run: pnpm install --ignore-scripts
30+
- name: Build
31+
run: pnpm build
32+
- name: Deploy
33+
uses: JamesIves/github-pages-deploy-action@6c2d9db40f9296374acc17b90404b6e8864128c8 # v4.7.3
34+
with:
35+
folder: test/demo/dist
36+
branch: gh-pages

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
node_modules/
2-
3-
coverage/
2+
dist/

README.md

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,27 @@
44
title="Philosopher’s stone, logo of PostCSS"
55
src="https://postcss.org/logo-leftp.svg">
66

7-
[PostCSS] plugin to generate more realistic [“smooth” shadows](https://tobiasahlin.com/blog/layered-smooth-box-shadows/).
7+
[PostCSS](https://github.com/postcss/postcss) plugin to generate more realistic [“smooth” shadows](https://tobiasahlin.com/blog/layered-smooth-box-shadows/).
88

99
```css
1010
.card {
11-
box-shadow: --smooth-shadow(#000, 10px, 2);
11+
box-shadow: --soft-shadow(0 1rem 2rem oklch(0 0 0 / 10%));
1212
}
1313
```
1414

1515
```css
1616
.card {
1717
box-shadow:
18-
0 calc(10px / 2) calc(10px / 2 * 2) oklch(from #000 l c h / 0.25),
19-
0 calc(10px / 2 * 2) calc(10px / 2 * 3) oklch(from #000 l c h / 0.18),
20-
0 calc(10px / 2 * 3) calc(10px / 2 * 4) oklch(from #000 l c h / 0.12);
18+
0 calc(0.0278 * 1rem) calc(0.0278 * 2rem) rgb(from oklch(0 0 0 / 10%) r g b / calc(alpha * 0.167)),
19+
0 calc(0.1111 * 1rem) calc(0.1111 * 2rem) rgb(from oklch(0 0 0 / 10%) r g b / calc(alpha * 0.333)),
20+
0 calc(0.25 * 1rem) calc(0.25 * 2rem) rgb(from oklch(0 0 0 / 10%) r g b / calc(alpha * 0.5)),
21+
0 calc(0.4444 * 1rem) calc(0.4444 * 2rem) rgb(from oklch(0 0 0 / 10%) r g b / calc(alpha * 0.667)),
22+
0 calc(0.6944 * 1rem) calc(0.6944 * 2rem) rgb(from oklch(0 0 0 / 10%) r g b / calc(alpha * 0.833)),
23+
0 calc(1 * 1rem) calc(1 * 2rem) rgb(from oklch(0 0 0 / 10%) r g b / calc(alpha * 1));
2124
}
2225
```
2326

24-
[postcss-utilities] collection is better for `clearfix` and other popular hacks.
25-
For simple cases you can use [postcss-define-property].
26-
27-
[postcss-define-property]: https://github.com/daleeidd/postcss-define-property
28-
[postcss-utilities]: https://github.com/ismamz/postcss-utilities
29-
[postcss-simple-vars]: https://github.com/postcss/postcss-simple-vars
30-
[postcss-nested]: https://github.com/postcss/postcss-nested
31-
[PostCSS]: https://github.com/postcss/postcss
27+
It supports non-px units like `rem`, 3 shadow types, inset shadows, and any color format (we recommends [`oklch()`](https://evilmartians.com/chronicles/oklch-in-css-why-quit-rgb-hsl)).
3228

3329
---
3430

@@ -64,3 +60,38 @@ module.exports = {
6460
]
6561
}
6662
```
63+
64+
### CSS API
65+
66+
The plugins supports 3 shadows types. You can try them on [`smoothshadows.com`](https://smoothshadows.com).
67+
68+
```css
69+
.soft {
70+
box-shadow: --soft-shadow(10px 0 8px oklch(0 0 0 / 10%));
71+
}
72+
.sharp {
73+
box-shadow: --sharp-shadow(10px 0 8px oklch(0 0 0 / 10%));
74+
}
75+
.linear {
76+
box-shadow: --linear-shadow(10px 0 8px oklch(0 0 0 / 10%));
77+
}
78+
```
79+
80+
It also supports `inset` shadows:
81+
82+
```css
83+
.inset {
84+
box-shadow: --soft-shadow(inset 10px 0 8px oklch(0 0 0 / 10%));
85+
}
86+
```
87+
88+
### JS API
89+
90+
There is low-level JS API:
91+
92+
```ts
93+
import { renderShadows } from 'postcss-smooth-shadow'
94+
95+
renderShadows('soft', false, '10px', '0', '8px', 'oklch(0 0 0 / 10%)')
96+
// => "0 calc(0.0278 * 1rem) calc(0.0278 * 2rem) rgb(from oklch(0 0 0 / 10%)…"
97+
```

index.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
import type { PluginCreator, AtRule } from 'postcss'
22

3+
export function renderShadows(
4+
type: 'linear' | 'sharp' | 'soft',
5+
inset: boolean,
6+
x: number,
7+
y: number,
8+
blur: number,
9+
color: string
10+
): string
11+
312
declare const plugin: PluginCreator<{}>
413

5-
export = plugin
14+
export default plugin

0 commit comments

Comments
 (0)