Skip to content

Commit

Permalink
Merge pull request #310 from ashik-75/work
Browse files Browse the repository at this point in the history
add svg & qrcode
  • Loading branch information
lifeparticle authored Sep 13, 2023
2 parents eb428c2 + 7990365 commit f0a2fd9
Show file tree
Hide file tree
Showing 17 changed files with 369 additions and 24 deletions.
4 changes: 3 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"tinycolor2": "^1.6.0",
"tinymce": "^6.6.2",
"values.js": "^2.1.1",
"web-vitals": "^3.3.1"
"web-vitals": "^3.3.1",
"webfontloader": "^1.6.28"
},
"scripts": {
"dev": "vite",
Expand Down Expand Up @@ -79,6 +80,7 @@
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@types/react-syntax-highlighter": "^15.5.7",
"@types/webfontloader": "^1.6.35",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.2.1",
"@vitejs/plugin-react": "^4.0.3",
Expand Down
12 changes: 12 additions & 0 deletions ui/src/components/Layouts/Menu/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export const MENU_ITEMS = [
icon: "Box",
show: IN_DEVELOPMENT,
},
{
name: "Svg Formatter",
url: "/css/svg-formatter",
icon: "Command",
show: IN_DEVELOPMENT,
},
],
},
{
Expand Down Expand Up @@ -91,6 +97,12 @@ export const MENU_ITEMS = [
icon: "BadgeHelp",
show: true,
},
{
name: "QR Code",
url: "/generator/qrcode",
icon: "QrCode",
show: true,
},
{
name: "Sorting",
url: "/generator/sorting",
Expand Down
19 changes: 19 additions & 0 deletions ui/src/pages/About/utils/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const LIBRARY_URLS: LibraryList = {
"https://www.npmjs.com/package/@uiw/react-md-editor",
tinymce: "https://www.npmjs.com/package/@tinymce/tinymce-react",
"values.js": "https://www.npmjs.com/package/values.js",
webfontloader: "https://www.npmjs.com/package/webfontloader",
};

const API_COLUMNS: ColumnsType<Api> = [
Expand Down Expand Up @@ -189,6 +190,13 @@ const FEATURE_DATA: Feature[] = [
link: "/css/br",
library: [{ name: "faker.js", url: LIBRARY_URLS["faker-js"] }],
},
{
key: "3",
name: "SVG Formatter",
description: "Merge svg path",
link: "/css/svg-formatter",
library: [{ name: "Vanilla JS", url: "" }],
},
{
key: "4",
name: "Base 64 Converter",
Expand Down Expand Up @@ -265,8 +273,19 @@ const FEATURE_DATA: Feature[] = [
name: "html-to-image",
url: LIBRARY_URLS["html-to-image"],
},
{
name: "webfontloader",
url: LIBRARY_URLS["webfontloader"],
},
],
},
{
key: "17",
name: "QR code generator",
description: "Generate QR code from text",
link: "/generator/qrcode",
library: [],
},
{
key: "10",
name: "Sorting",
Expand Down
6 changes: 3 additions & 3 deletions ui/src/pages/CSS/BorderRadius/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const BorderRadius = () => {
};

return (
<Space direction="vertical">
<>
<PageGrid className={style.br}>
<Card className={style.br__input}>
<Form layout="vertical">
Expand Down Expand Up @@ -206,13 +206,13 @@ const BorderRadius = () => {
</Space>
</Card>
</PageGrid>
<Card>
<Card style={{ marginTop: "20px" }}>
<CodeHighlightWithCopy
codeString={generateCSSCodeString()}
language="css"
/>
</Card>
</Space>
</>
);
};

Expand Down
49 changes: 49 additions & 0 deletions ui/src/pages/CSS/SvgFormatter/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Card, Form, Input } from "antd";
import CodeHighlightWithCopy from "components/General/CodeHighlightWithCopy";
import PageGrid from "components/Layouts/PageGrid";
import React, { ChangeEvent, useState } from "react";
import { combineSVGPaths } from "./utils/helper";

const { TextArea } = Input;

const SvgFormatter: React.FC = () => {
const [value, setValue] = useState("");
const [outputSVG, setOutputSVG] = useState<string>("");

const handleChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
const newValue = e.target.value;
setValue(newValue);

const combinedSvgOutput = combineSVGPaths(newValue);
setOutputSVG(combinedSvgOutput);
};
return (
<PageGrid>
<Card>
<Form layout="vertical">
<Form.Item label="Svg Input">
<TextArea
placeholder="Enter svg value"
value={value}
rows={10}
onChange={handleChange}
data-gramm={false}
allowClear
/>
</Form.Item>
</Form>
</Card>

{outputSVG && (
<Card>
<CodeHighlightWithCopy
language="css"
codeString={outputSVG}
/>
</Card>
)}
</PageGrid>
);
};

export default SvgFormatter;
35 changes: 35 additions & 0 deletions ui/src/pages/CSS/SvgFormatter/utils/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
function combineSVGPaths(svgInput: string): string {
try {
const parser = new DOMParser();
const svgDocument = parser.parseFromString(svgInput, "image/svg+xml");

const pathElements = svgDocument.querySelectorAll("path");

if (pathElements.length === 0) {
throw new Error("No <path> elements found in the SVG.");
}

const pathDataArray = Array.from(pathElements).map((path) =>
path.getAttribute("d")
);

const combinedPathData = pathDataArray.join("\n");
const svgElement = svgDocument.querySelector("svg");

if (svgElement) {
svgElement.innerHTML = `<path d="${combinedPathData}" stroke="#F0F" />`;
} else {
throw new Error("<svg> element not found in the SVG.");
}

const serializer = new XMLSerializer();
const combinedSVGString = serializer.serializeToString(svgDocument);

return combinedSVGString;
} catch (error) {
console.error(error);
return "Error combining SVG paths.";
}
}

export { combineSVGPaths };
11 changes: 6 additions & 5 deletions ui/src/pages/Colors/ColorPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ const ColorPicker: React.FC = () => {
clipboardComponent={ClipboardButton}
/>
</CopyInput>

<ColorFormatTags
currentFormat={format}
onSelect={setFormat}
/>
<Form.Item label="Color format">
<ColorFormatTags
currentFormat={format}
onSelect={setFormat}
/>
</Form.Item>

<CP
format={format}
Expand Down
35 changes: 28 additions & 7 deletions ui/src/pages/Data/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@ import { saveAs } from "file-saver";
import { toPng } from "html-to-image";
import { Card, Form, Slider, Avatar as AntAvatar, Space } from "antd";
import ColorPickerWithInput from "components/General/ColorPickerWithInput";
import WebFont from "webfontloader";
import {
ResponsiveButton,
ResponsiveInputWithLabel,
ResponsiveSegementWithLabel,
ResponsiveSelectWithLabel,
} from "components/General/FormComponents";
import PageGrid from "components/Layouts/PageGrid";
import { useRef, useState } from "react";
import {
AVATAR_SHAPE_SEGMENTED_OPTIONS,
AvatarShape,
AvatarShapeType,
FONTS,
} from "./utils/constants";
import InputGrid from "components/Layouts/InputGrid";
import style from "./Avatar.module.scss";

const Avatar = () => {
const [text, setText] = useState<string>("BT");
const [avatarFont, setAvatarFont] = useState(FONTS[0].value);
const [textColor, setTextColor] = useState<string>(
"rgba(255, 255, 255, 1)"
);
Expand All @@ -41,6 +45,12 @@ const Avatar = () => {
saveAs(blob, `image-${Date.now()}.png`);
};

// Load the selected font when it changes
WebFont.load({
google: {
families: [avatarFont],
},
});
return (
<PageGrid>
<Card>
Expand Down Expand Up @@ -69,12 +79,13 @@ const Avatar = () => {
</InputGrid>

<InputGrid>
<ResponsiveInputWithLabel
label="Avatar size"
placeholder="Enter avatar size"
value={avatarSize}
onChange={(val) => setAvatarSize(val || 0)}
type="number"
<ResponsiveSelectWithLabel
label="Font family"
value={avatarFont}
options={FONTS}
onSelect={(_, info) => {
setAvatarFont(info.value);
}}
/>

<ResponsiveInputWithLabel
Expand All @@ -87,6 +98,13 @@ const Avatar = () => {
</InputGrid>

<InputGrid>
<ResponsiveInputWithLabel
label="Avatar size"
placeholder="Enter avatar size"
value={avatarSize}
onChange={(val) => setAvatarSize(val || 0)}
type="number"
/>
<ResponsiveSegementWithLabel
value={shapeType}
label="Avatar shape"
Expand All @@ -97,6 +115,8 @@ const Avatar = () => {
}
}}
/>
</InputGrid>
<div>
{shapeType === AvatarShape.Custom && (
<Form.Item label="Avatar border radius">
<Slider
Expand All @@ -109,7 +129,7 @@ const Avatar = () => {
/>
</Form.Item>
)}
</InputGrid>
</div>
</Form>
</Card>

Expand All @@ -127,6 +147,7 @@ const Avatar = () => {
? `${customBorderRadius}px`
: "",
fontSize,
fontFamily: avatarFont,
}}
>
{text}
Expand Down
24 changes: 23 additions & 1 deletion ui/src/pages/Data/Avatar/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ const AVATAR_SHAPE_SEGMENTED_OPTIONS = [
{ label: "Custom", value: AvatarShape.Custom },
];

const FONTS = [
{ value: "Open Sans", label: "Open Sans" },
{ value: "Roboto", label: "Roboto" },
{ value: "Lato", label: "Lato" },
{ value: "Source Sans Pro", label: "Source Sans Pro" },
{ value: "Nunito Sans", label: "Nunito Sans" },
{ value: "Poppins", label: "Poppins" },
{ value: "Montserrat", label: "Montserrat" },
{ value: "Raleway", label: "Raleway" },
{ value: "Oswald", label: "Oswald" },
{ value: "Merriweather", label: "Merriweather" },
{ value: "Playfair Display", label: "Playfair Display" },
{ value: "Dancing Script", label: "Dancing Script" },
{ value: "Cormorant Garamond", label: "Cormorant Garamond" },
{ value: "Fira Sans", label: "Fira Sans" },
{ value: "Karla", label: "Karla" },
{ value: "Ubuntu", label: "Ubuntu" },
{ value: "Inconsolata", label: "Inconsolata" },
{ value: "PT Sans", label: "PT Sans" },
{ value: "Quicksand", label: "Quicksand" },
];

export type { AvatarShapeType };

export { AVATAR_SHAPE_SEGMENTED_OPTIONS, AvatarShape };
export { AVATAR_SHAPE_SEGMENTED_OPTIONS, AvatarShape, FONTS };
23 changes: 23 additions & 0 deletions ui/src/pages/Data/QRcode/QRcode.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.qrcode {
&__label {
display: flex;
width: 100vw;
justify-content: space-between;
}

&__output {
height: 266px;
&__result,
&__notfound {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

&__notfound {
height: 200px;
text-align: center;
}
}
}
Loading

0 comments on commit f0a2fd9

Please sign in to comment.