Skip to content

Commit

Permalink
Merge pull request #248 from hepengwei/feat_he
Browse files Browse the repository at this point in the history
新增生成阴影菜单模块
  • Loading branch information
hepengwei authored Apr 26, 2024
2 parents b41eaaf + bf9c801 commit 1cf4bba
Show file tree
Hide file tree
Showing 13 changed files with 344 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/styles/main.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/global.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
$globalPrimaryColor: #4c78fc;
$globalPrimaryColor2: #224141;
$buttonColor: #35a2fd;
$buttonColor2: #35a2fd44;
$headHeight: 60px;
Expand Down
6 changes: 6 additions & 0 deletions src/layout/Menus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ const Menus: React.FC = () => {
}),
"generateRegularPolygon"
),
getItem(
intl.formatMessage({
id: "menu.cssDynamicEffect.generateShadow",
}),
"generateShadow"
),
// getItem(
// intl.formatMessage({
// id: "menu.cssDynamicEffect.musicVisualization",
Expand Down
6 changes: 6 additions & 0 deletions src/locale/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const en_US = {
"menu.cssDynamicEffect.dynamicEffectButton": "Dynamic Effect Button",
"menu.cssDynamicEffect.richDynamicEffect": "Rich Dynamic Effect",
"menu.cssDynamicEffect.generateRegularPolygon": "Generate Regular Polygon",
"menu.cssDynamicEffect.generateShadow": "Generate Shadow",
"menu.cssDynamicEffect.musicVisualization": "Music Visualization",
"menu.canvasDynamicEffect": "Canvas Dynamic Effect",
"menu.canvasDynamicEffect.sphereCollisionExample": "sphere-collision Example",
Expand Down Expand Up @@ -261,6 +262,11 @@ const en_US = {
"page.cssDynamicEffect.generateRegularPolygon.numberOfSides":
"Number of sides",
"page.cssDynamicEffect.generateRegularPolygon.rotation": "Rotation",
"page.cssDynamicEffect.generateShadow.horizontalOffset": "Horizontal Offset",
"page.cssDynamicEffect.generateShadow.verticalOffset": "Vertical Offset",
"page.cssDynamicEffect.generateShadow.blurLength": "Blur Length",
"page.cssDynamicEffect.generateShadow.shadowSize": "Shadow Size",
"page.cssDynamicEffect.generateShadow.borderRadius": "Border Radius",

// Canvas动效
"page.canvasDynamicEffect.sphereCollisionExample": "sphere-collision example",
Expand Down
6 changes: 6 additions & 0 deletions src/locale/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const zh_CN = {
"menu.cssDynamicEffect.dynamicEffectButton": "动效按钮",
"menu.cssDynamicEffect.richDynamicEffect": "丰富动效",
"menu.cssDynamicEffect.generateRegularPolygon": "生成正多边形",
"menu.cssDynamicEffect.generateShadow": "生成阴影",
"menu.cssDynamicEffect.musicVisualization": "音乐可视化",
"menu.canvasDynamicEffect": "Canvas动效",
"menu.canvasDynamicEffect.sphereCollisionExample": "sphere-collision库示例",
Expand Down Expand Up @@ -224,6 +225,11 @@ const zh_CN = {
"page.cssDynamicEffect.richDynamicEffect.tankShaking": "水罐摇晃动效",
"page.cssDynamicEffect.generateRegularPolygon.numberOfSides": "边数",
"page.cssDynamicEffect.generateRegularPolygon.rotation": "旋转",
"page.cssDynamicEffect.generateShadow.horizontalOffset": "水平偏移",
"page.cssDynamicEffect.generateShadow.verticalOffset": "垂直偏移",
"page.cssDynamicEffect.generateShadow.blurLength": "模糊程度",
"page.cssDynamicEffect.generateShadow.shadowSize": "阴影大小",
"page.cssDynamicEffect.generateShadow.borderRadius": "边框半径",

// Canvas动效
"page.canvasDynamicEffect.sphereCollisionExample": "sphere-collision库示例",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/css/GenerateRegularPolygon/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
width: 100%;
margin-bottom: 20px;
.label {
color: #444;
color: #333 !important;
margin-right: 6px;
font-size: 15px;
color: #666;
Expand Down
8 changes: 0 additions & 8 deletions src/pages/css/GenerateRegularPolygon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ const GenerateRegularPolygon = () => {
</div>
<div className={styles.codeBox}>
<span>{".box {"}</span>
<span>
&nbsp;&nbsp;&nbsp;&nbsp;width:{" "}
{graphRef.current ? graphRef.current.clientWidth : 0}px;
</span>
<span>
&nbsp;&nbsp;&nbsp;&nbsp;height:{" "}
{graphRef.current ? graphRef.current.clientWidth : 0}px;
</span>
<span>
&nbsp;&nbsp;&nbsp;&nbsp;background: linear-gradient(135deg,
#112437, #1d3450, #29588a, #116d6e, #5c8984, #47a992) fixed;
Expand Down
76 changes: 76 additions & 0 deletions src/pages/css/GenerateShadow/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.container {
display: flex;
justify-content: center;
align-items: center;
padding-top: 30px;
padding-bottom: 20px;
overflow-y: auto;
.content {
display: flex;
flex-direction: column;

$boxWidth: 800px;
$boxHeight: 380px;
$boxPadding: 60px;
.box {
box-sizing: border-box;
display: flex;
justify-content: center;
align-items: center;
width: $boxWidth;
height: $boxHeight;
border: 2px dashed #73828c;
padding: $boxPadding;
.graph {
box-sizing: border-box;
width: $boxHeight - 2 * $boxPadding;
height: $boxHeight - 2 * $boxPadding;
background: linear-gradient(
135deg,
#112437,
#1d3450,
#29588a,
#116d6e,
#5c8984,
#47a992
)
fixed;
box-shadow: var(--boxShadow);
}
}
.bottom {
width: $boxWidth;
display: flex;
flex-direction: column;
margin-top: 20px;
.row {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
margin-bottom: 20px;
.rowItem {
display: flex;
align-items: center;
width: 47%;
.label {
color: #333 !important;
margin-right: 6px;
font-size: 15px;
color: #666;
}
}
}
.codeBox {
width: 100%;
max-width: 100%;
overflow-x: auto;
background-color: #8bacaa;
padding: 10px;
color: #222;
display: flex;
flex-direction: column;
}
}
}
}
239 changes: 239 additions & 0 deletions src/pages/css/GenerateShadow/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/**
* 生成阴影
*/
import React, { useEffect, useRef, useState } from "react";
import { Slider, InputNumber, message } from "antd";
import { useIntl } from "react-intl";
import styles from "./index.module.scss";

const minSideNum = -50;
const maxSideNum = 50;
const defaultHorizontalValue = 20;
const defaultVerticalValue = 20;
const defaultBlurLength = 10;
const defaultSpreadSize = 0;
const defaultBorderRadius = 20;

const GenerateShadow = () => {
const intl = useIntl();
const graphRef = useRef<HTMLDivElement>(null);
const [horizontalValue, setHorizontalValue] = useState<number>(
defaultHorizontalValue
); // 水平阴影位置
const [verticalValue, setVerticalValue] =
useState<number>(defaultVerticalValue); // 垂直阴影位置
const [blurLength, setBlurLength] = useState<number>(defaultBlurLength); // 模糊程度
const [shadowSize, setShadowSize] = useState<number>(defaultSpreadSize); // 阴影大小
const [borderRadius, setBorderRadius] = useState<number>(defaultBorderRadius); // 边框半价

const [boxShadowStr, setBoxShadowStr] = useState<string>("");

const onHorizontalValueChange = (value: number | null) => {
setHorizontalValue(value || value === 0 ? value : defaultHorizontalValue);
};

const onVerticalValueChange = (value: number | null) => {
setVerticalValue(value || value === 0 ? value : defaultVerticalValue);
};

const onBlurLengthChange = (value: number | null) => {
setBlurLength(value || value === 0 ? value : defaultBlurLength);
};

const onShadowSizeChange = (value: number | null) => {
setShadowSize(value || value === 0 ? value : defaultSpreadSize);
};

const onBorderRadiusChange = (value: number | null) => {
setBorderRadius(value || value === 0 ? value : defaultBorderRadius);
};

useEffect(() => {
if (graphRef.current) {
const boxShadowStr = `${horizontalValue}px ${verticalValue}px ${blurLength}px ${shadowSize}px #224141`;
graphRef.current.style.setProperty("--boxShadow", boxShadowStr);
setBoxShadowStr(boxShadowStr);
}
}, [horizontalValue, verticalValue, blurLength, shadowSize]);

return (
<div className={styles.container}>
<div className={styles.content}>
<div className={styles.box}>
<div
className={styles.graph}
style={{ borderRadius: `${borderRadius}px` }}
ref={graphRef}
/>
</div>
<div className={styles.bottom}>
<div className={styles.row}>
<div className={styles.rowItem}>
<span className={styles.label}>
{intl.formatMessage({
id: "page.cssDynamicEffect.generateShadow.horizontalOffset",
})}
:
</span>
<Slider
style={{
display: "flex",
flex: 1,
marginLeft: "10px",
marginRight: "16px",
}}
min={minSideNum}
max={maxSideNum}
step={1}
value={horizontalValue}
onChange={onHorizontalValueChange}
/>
<InputNumber
style={{ width: "80px" }}
min={minSideNum}
max={maxSideNum}
precision={0}
value={horizontalValue}
onChange={onHorizontalValueChange}
/>
</div>
<div className={styles.rowItem}>
<span className={styles.label}>
{intl.formatMessage({
id: "page.cssDynamicEffect.generateShadow.verticalOffset",
})}
:
</span>
<Slider
style={{
display: "flex",
flex: 1,
marginLeft: "10px",
marginRight: "16px",
}}
min={minSideNum}
max={maxSideNum}
step={1}
value={verticalValue}
onChange={onVerticalValueChange}
/>
<InputNumber
style={{ width: "80px" }}
min={minSideNum}
max={maxSideNum}
precision={0}
value={verticalValue}
onChange={onVerticalValueChange}
/>
</div>
</div>
<div className={styles.row}>
<div className={styles.rowItem}>
<span className={styles.label}>
{intl.formatMessage({
id: "page.cssDynamicEffect.generateShadow.blurLength",
})}
:
</span>
<Slider
style={{
display: "flex",
flex: 1,
marginLeft: "10px",
marginRight: "16px",
}}
min={0}
max={maxSideNum}
step={1}
value={blurLength}
onChange={onBlurLengthChange}
/>
<InputNumber
style={{ width: "80px" }}
min={0}
max={maxSideNum}
precision={0}
value={blurLength}
onChange={onBlurLengthChange}
/>
</div>
<div className={styles.rowItem}>
<span className={styles.label}>
{intl.formatMessage({
id: "page.cssDynamicEffect.generateShadow.shadowSize",
})}
:
</span>
<Slider
style={{
display: "flex",
flex: 1,
marginLeft: "10px",
marginRight: "16px",
}}
min={minSideNum}
max={maxSideNum}
step={1}
value={shadowSize}
onChange={onShadowSizeChange}
/>
<InputNumber
style={{ width: "80px" }}
min={minSideNum}
max={maxSideNum}
precision={0}
value={shadowSize}
onChange={onShadowSizeChange}
/>
</div>
</div>
<div className={styles.row}>
<div className={styles.rowItem}>
<span className={styles.label}>
{intl.formatMessage({
id: "page.cssDynamicEffect.generateShadow.borderRadius",
})}
:
</span>
<Slider
style={{
display: "flex",
flex: 1,
marginLeft: "10px",
marginRight: "16px",
}}
min={0}
max={maxSideNum}
step={1}
value={borderRadius}
onChange={onBorderRadiusChange}
/>
<InputNumber
style={{ width: "80px" }}
min={0}
max={maxSideNum}
precision={0}
value={borderRadius}
onChange={onBorderRadiusChange}
/>
</div>
</div>
<div className={styles.codeBox}>
<span>{".box {"}</span>
<span>
&nbsp;&nbsp;&nbsp;&nbsp;background: linear-gradient(135deg,
#112437, #1d3450, #29588a, #116d6e, #5c8984, #47a992) fixed;
</span>
<span>&nbsp;&nbsp;&nbsp;&nbsp;box-shadow: {boxShadowStr};</span>
<span>
&nbsp;&nbsp;&nbsp;&nbsp;border-radius: {borderRadius}px;
</span>
<span>{"}"}</span>
</div>
</div>
</div>
</div>
);
};

export default GenerateShadow;
Loading

0 comments on commit 1cf4bba

Please sign in to comment.