Skip to content

Commit

Permalink
fix: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
swernerx committed Jul 31, 2024
1 parent 1c8b20e commit 65ee120
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 118 deletions.
6 changes: 1 addition & 5 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import type { StorybookConfig } from "@storybook/react-vite"

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions"
],
addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
framework: {
name: "@storybook/react-vite",
options: {}
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@
"bezier-easing": "^2.1.0"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.6.1",
"@storybook/addon-essentials": "^8.2.6",
"@storybook/addon-interactions": "^8.2.6",
"@storybook/addon-links": "^8.2.6",
"@storybook/blocks": "^8.2.6",
"@storybook/react": "^8.2.6",
Expand Down
78 changes: 0 additions & 78 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 33 additions & 33 deletions src/factory.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import bezierEasing from "bezier-easing";
import bezierEasing from "bezier-easing"

export type EasingValue = [number, number, number, number];
export type EasingValue = [number, number, number, number]

export interface ShadowConfig {
shadowLayers: number;
shadowLayers: number

finalOffsetX: number;
finalOffsetY: number;
offsetEasing: EasingValue;
finalOffsetX: number
finalOffsetY: number
offsetEasing: EasingValue

finalBlur: number;
blurEasing: EasingValue;
finalBlur: number
blurEasing: EasingValue

finalAlpha: number;
alphaEasing: EasingValue;
reverseAlpha: boolean;
finalAlpha: number
alphaEasing: EasingValue
reverseAlpha: boolean
}

const defaults: ShadowConfig = {
Expand All @@ -29,46 +29,46 @@ const defaults: ShadowConfig = {

finalAlpha: 0.2,
reverseAlpha: false,
alphaEasing: [0.1, 0.5, 0.9, 0.5],
};
alphaEasing: [0.1, 0.5, 0.9, 0.5]
}

export type ShadowValues = [number, number, number, number];
export type ShadowSet = ShadowValues[];
export type ShadowValues = [number, number, number, number]
export type ShadowSet = ShadowValues[]

export function buildShadow(config: Partial<ShadowConfig>): ShadowSet {
const cfg = { ...defaults, ...config };
const cfg = { ...defaults, ...config }

const alphaEasing = bezierEasing(...cfg.alphaEasing);
const offsetEasing = bezierEasing(...cfg.offsetEasing);
const blurEasing = bezierEasing(...cfg.blurEasing);
const alphaEasing = bezierEasing(...cfg.alphaEasing)
const offsetEasing = bezierEasing(...cfg.offsetEasing)
const blurEasing = bezierEasing(...cfg.blurEasing)

const easedAlphaValues = [];
const easedOffsetValues = [];
const easedBlurValues = [];
const easedAlphaValues = []
const easedOffsetValues = []
const easedBlurValues = []

for (let i = 1; i <= cfg.shadowLayers; i++) {
const fraction = i / cfg.shadowLayers;
const fraction = i / cfg.shadowLayers
if (cfg.reverseAlpha) {
easedAlphaValues.unshift(alphaEasing(fraction));
easedAlphaValues.unshift(alphaEasing(fraction))
} else {
easedAlphaValues.push(alphaEasing(fraction));
easedAlphaValues.push(alphaEasing(fraction))
}

easedOffsetValues.push(offsetEasing(fraction));
easedBlurValues.push(blurEasing(fraction));
easedOffsetValues.push(offsetEasing(fraction))
easedBlurValues.push(blurEasing(fraction))
}

const boxShadowValues: ShadowSet = [];
const boxShadowValues: ShadowSet = []
for (let i = 0; i < cfg.shadowLayers; i++) {
boxShadowValues.push([
easedOffsetValues[i] * cfg.finalOffsetX,
easedOffsetValues[i] * cfg.finalOffsetY,
easedBlurValues[i] * cfg.finalBlur,
easedAlphaValues[i] * cfg.finalAlpha,
]);
easedAlphaValues[i] * cfg.finalAlpha
])
}

return boxShadowValues;
return boxShadowValues
}

export function toBoxShadow(shadowSet: ShadowSet, precision = 3): string {
Expand All @@ -81,7 +81,7 @@ export function toBoxShadow(shadowSet: ShadowSet, precision = 3): string {
precision
)})`
)
.join(",");
.join(",")
}

export function toDropShadow(shadowSet: ShadowSet, precision = 3): string {
Expand All @@ -98,5 +98,5 @@ export function toDropShadow(shadowSet: ShadowSet, precision = 3): string {
alpha * 1.1
).toFixed(precision)}))`
)
.join(" ");
.join(" ")
}

0 comments on commit 65ee120

Please sign in to comment.