mirror of
https://github.com/zhigang1992/nativewind.git
synced 2026-06-16 19:51:20 +08:00
feat: support 'shadow'
This commit is contained in:
@@ -1,15 +1,103 @@
|
|||||||
import { expectError, tailwindRunner } from "./runner";
|
import { expectError, tailwindRunner } from "./runner";
|
||||||
|
|
||||||
tailwindRunner(
|
tailwindRunner("Effects - Box Shadow", [
|
||||||
"Effects - Box Shadow",
|
[
|
||||||
expectError([
|
|
||||||
"shadow-sm",
|
"shadow-sm",
|
||||||
|
{
|
||||||
|
styles: {
|
||||||
|
"shadow-sm": {
|
||||||
|
shadowColor: "rgba(0, 0, 0, 0.1)",
|
||||||
|
shadowOffset: { height: 1, width: 0 },
|
||||||
|
shadowOpacity: 1,
|
||||||
|
shadowRadius: 1,
|
||||||
|
elevation: 1.5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
"shadow",
|
"shadow",
|
||||||
|
{
|
||||||
|
styles: {
|
||||||
|
shadow: {
|
||||||
|
shadowColor: "rgba(0, 0, 0, 0.1)",
|
||||||
|
shadowOffset: { height: 4, width: 0 },
|
||||||
|
shadowOpacity: 1,
|
||||||
|
shadowRadius: 6,
|
||||||
|
elevation: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
"shadow-md",
|
"shadow-md",
|
||||||
|
{
|
||||||
|
styles: {
|
||||||
|
"shadow-md": {
|
||||||
|
shadowColor: "rgba(0, 0, 0, 0.1)",
|
||||||
|
shadowOffset: { height: 6, width: 0 },
|
||||||
|
shadowOpacity: 1,
|
||||||
|
shadowRadius: 10,
|
||||||
|
elevation: 6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
"shadow-lg",
|
"shadow-lg",
|
||||||
|
{
|
||||||
|
styles: {
|
||||||
|
"shadow-lg": {
|
||||||
|
shadowColor: "rgba(0, 0, 0, 0.1)",
|
||||||
|
shadowOffset: { height: 10, width: 0 },
|
||||||
|
shadowOpacity: 1,
|
||||||
|
shadowRadius: 15,
|
||||||
|
elevation: 7.5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
"shadow-xl",
|
"shadow-xl",
|
||||||
|
{
|
||||||
|
styles: {
|
||||||
|
"shadow-xl": {
|
||||||
|
shadowColor: "rgba(0, 0, 0, 0.1)",
|
||||||
|
shadowOffset: { height: 20, width: 0 },
|
||||||
|
shadowOpacity: 1,
|
||||||
|
shadowRadius: 25,
|
||||||
|
elevation: 12.5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
"shadow-2xl",
|
"shadow-2xl",
|
||||||
"shadow-inner",
|
{
|
||||||
|
styles: {
|
||||||
|
"shadow-2xl": {
|
||||||
|
shadowColor: "rgba(0, 0, 0, 0.1)",
|
||||||
|
shadowOffset: { height: 25, width: 0 },
|
||||||
|
shadowOpacity: 1,
|
||||||
|
shadowRadius: 50,
|
||||||
|
elevation: 25,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
"shadow-none",
|
"shadow-none",
|
||||||
])
|
{
|
||||||
);
|
styles: {
|
||||||
|
"shadow-none": {
|
||||||
|
shadowColor: "rgba(0, 0, 0, 0)",
|
||||||
|
shadowOffset: { height: 0, width: 0 },
|
||||||
|
shadowOpacity: 1,
|
||||||
|
shadowRadius: 0,
|
||||||
|
elevation: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
...expectError(["shadow-inner"]),
|
||||||
|
]);
|
||||||
|
|||||||
28
src/plugin/native/box-shadow.ts
Normal file
28
src/plugin/native/box-shadow.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { CustomPluginFunction } from "./types";
|
||||||
|
|
||||||
|
export const boxShadow: CustomPluginFunction = (
|
||||||
|
{ matchUtilities, theme },
|
||||||
|
notSupported
|
||||||
|
) => {
|
||||||
|
const themeValues = Object.entries(theme("boxShadow"));
|
||||||
|
const elevation = theme("elevation");
|
||||||
|
|
||||||
|
matchUtilities(
|
||||||
|
{
|
||||||
|
shadow(value: string) {
|
||||||
|
const size = themeValues.find(([, themeValue]) => value === themeValue);
|
||||||
|
|
||||||
|
return size
|
||||||
|
? {
|
||||||
|
boxShadow: value,
|
||||||
|
elevation: elevation[size[0]],
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
boxShadow: value,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
"shadow-inner": notSupported("shadow-inner"),
|
||||||
|
},
|
||||||
|
{ values: theme("boxShadow"), type: ["shadow"] }
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
TailwindThemeValue,
|
TailwindThemeValue,
|
||||||
} from "tailwindcss/tailwind-config";
|
} from "tailwindcss/tailwind-config";
|
||||||
import { StyleError } from "../../types/common";
|
import { StyleError } from "../../types/common";
|
||||||
|
import { boxShadow } from "./box-shadow";
|
||||||
import { divide } from "./divide";
|
import { divide } from "./divide";
|
||||||
import { elevation } from "./elevation";
|
import { elevation } from "./elevation";
|
||||||
import { fontSize } from "./font-size";
|
import { fontSize } from "./font-size";
|
||||||
@@ -42,6 +43,7 @@ export const nativePlugin = plugin.withOptions<NativePluginOptions | undefined>(
|
|||||||
rotate(helpers, notSupported);
|
rotate(helpers, notSupported);
|
||||||
translate(helpers, notSupported);
|
translate(helpers, notSupported);
|
||||||
skew(helpers, notSupported);
|
skew(helpers, notSupported);
|
||||||
|
boxShadow(helpers, notSupported);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
function ({ rem = 16 } = {}) {
|
function ({ rem = 16 } = {}) {
|
||||||
@@ -165,11 +167,21 @@ export const nativePlugin = plugin.withOptions<NativePluginOptions | undefined>(
|
|||||||
elevation: {
|
elevation: {
|
||||||
sm: "1.5",
|
sm: "1.5",
|
||||||
DEFAULT: "3",
|
DEFAULT: "3",
|
||||||
|
md: "6",
|
||||||
lg: "7.5",
|
lg: "7.5",
|
||||||
xl: "12.5",
|
xl: "12.5",
|
||||||
"2xl": "25",
|
"2xl": "25",
|
||||||
none: "0",
|
none: "0",
|
||||||
},
|
},
|
||||||
|
boxShadow: {
|
||||||
|
sm: "0px 1px 1px rgba(0, 0, 0, 0.1)",
|
||||||
|
DEFAULT: "0px 4px 6px rgba(0, 0, 0, 0.1)",
|
||||||
|
md: "0px 6px 10px rgba(0, 0, 0, 0.1)",
|
||||||
|
lg: "0px 10px 15px rgba(0, 0, 0, 0.1)",
|
||||||
|
xl: "0px 20px 25px rgba(0, 0, 0, 0.1)",
|
||||||
|
"2xl": "0px 25px 50px rgba(0, 0, 0, 0.1)",
|
||||||
|
none: "0px 0px 0px rgba(0, 0, 0, 0)",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
corePlugins: {
|
corePlugins: {
|
||||||
space: false,
|
space: false,
|
||||||
@@ -184,6 +196,7 @@ export const nativePlugin = plugin.withOptions<NativePluginOptions | undefined>(
|
|||||||
rotate: false,
|
rotate: false,
|
||||||
skew: false,
|
skew: false,
|
||||||
translate: false,
|
translate: false,
|
||||||
|
boxShadow: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user