|
4 | 4 | title="Philosopher’s stone, logo of PostCSS" |
5 | 5 | src="https://postcss.org/logo-leftp.svg"> |
6 | 6 |
|
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/). |
8 | 8 |
|
9 | 9 | ```css |
10 | 10 | .card { |
11 | | - box-shadow: --smooth-shadow(#000, 10px, 2); |
| 11 | + box-shadow: --soft-shadow(0 1rem 2rem oklch(0 0 0 / 10%)); |
12 | 12 | } |
13 | 13 | ``` |
14 | 14 |
|
15 | 15 | ```css |
16 | 16 | .card { |
17 | 17 | 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)); |
21 | 24 | } |
22 | 25 | ``` |
23 | 26 |
|
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)). |
32 | 28 |
|
33 | 29 | --- |
34 | 30 |
|
@@ -64,3 +60,38 @@ module.exports = { |
64 | 60 | ] |
65 | 61 | } |
66 | 62 | ``` |
| 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 | +``` |
0 commit comments