diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 215a0c3..4c1febc 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,12 +4,12 @@
-
+
-
-
+
+
@@ -265,15 +265,7 @@
-
-
-
-
- 1719587281298
-
-
-
- 1719587281298
+
@@ -659,7 +651,15 @@
1740614957672
-
+
+
+ 1740619610168
+
+
+
+ 1740619610169
+
+
@@ -691,7 +691,6 @@
-
@@ -716,7 +715,8 @@
-
+
+
diff --git a/src/components/examples/ExampleCard.tsx b/src/components/examples/ExampleCard.tsx
index 69523c9..bbcffad 100644
--- a/src/components/examples/ExampleCard.tsx
+++ b/src/components/examples/ExampleCard.tsx
@@ -1,4 +1,3 @@
-import { ExampleCardProps } from './Examples';
import {
Box,
Card,
@@ -9,14 +8,25 @@ import {
useTheme
} from '@mui/material';
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
-import RequiredOptions from './RequiredOptions';
+import ExampleOptions from './ExampleOptions';
+import { GetGroupsType } from '@components/options/ToolOptions';
+
+export interface ExampleCardProps {
+ title: string;
+ description: string;
+ sampleText: string;
+ sampleResult: string;
+ sampleOptions: T;
+ changeInputResult: (newOptions: T) => void;
+ getGroups: GetGroupsType;
+}
export default function ExampleCard({
title,
description,
sampleText,
sampleResult,
- requiredOptions,
+ sampleOptions,
changeInputResult,
getGroups
}: ExampleCardProps) {
@@ -25,7 +35,7 @@ export default function ExampleCard({
{
- changeInputResult(sampleText, sampleResult);
+ changeInputResult(sampleOptions);
}}
sx={{
bgcolor: theme.palette.background.default,
@@ -108,7 +118,7 @@ export default function ExampleCard({
/>
-
+
diff --git a/src/components/examples/RequiredOptions.tsx b/src/components/examples/ExampleOptions.tsx
similarity index 58%
rename from src/components/examples/RequiredOptions.tsx
rename to src/components/examples/ExampleOptions.tsx
index 1f83ecb..cac9c94 100644
--- a/src/components/examples/RequiredOptions.tsx
+++ b/src/components/examples/ExampleOptions.tsx
@@ -2,12 +2,18 @@ import ToolOptionGroups from '@components/options/ToolOptionGroups';
import { GetGroupsType } from '@components/options/ToolOptions';
import React from 'react';
-export default function RequiredOptions({
+export default function ExampleOptions({
options,
getGroups
}: {
options: T;
getGroups: GetGroupsType;
}) {
- return ;
+ return (
+
+ );
}
diff --git a/src/components/examples/Examples.tsx b/src/components/examples/Examples.tsx
index fef6660..bb56777 100644
--- a/src/components/examples/Examples.tsx
+++ b/src/components/examples/Examples.tsx
@@ -1,24 +1,14 @@
import { Box, Grid, Stack, Typography } from '@mui/material';
-import ExampleCard from './ExampleCard';
+import ExampleCard, { ExampleCardProps } from './ExampleCard';
import React from 'react';
import { GetGroupsType } from '@components/options/ToolOptions';
-export interface ExampleCardProps {
- title: string;
- description: string;
- sampleText: string;
- sampleResult: string;
- requiredOptions: T;
- changeInputResult: (input: string, result: string) => void;
- getGroups: GetGroupsType;
-}
-
interface ExampleProps {
title: string;
subtitle: string;
- exampleCards: ExampleCardProps[];
+ exampleCards: Omit, 'getGroups' | 'changeInputResult'>[];
getGroups: GetGroupsType;
- changeInputResult: (input: string, result: string) => void;
+ changeInputResult: (newOptions: T) => void;
}
export default function Examples({
@@ -48,7 +38,7 @@ export default function Examples({
description={card.description}
sampleText={card.sampleText}
sampleResult={card.sampleResult}
- requiredOptions={card.requiredOptions}
+ sampleOptions={card.sampleOptions}
getGroups={getGroups}
changeInputResult={changeInputResult}
/>
diff --git a/src/components/options/ToolOptionGroups.tsx b/src/components/options/ToolOptionGroups.tsx
index 3f98bbd..d594a00 100644
--- a/src/components/options/ToolOptionGroups.tsx
+++ b/src/components/options/ToolOptionGroups.tsx
@@ -8,14 +8,16 @@ export interface ToolOptionGroup {
}
export default function ToolOptionGroups({
- groups
+ groups,
+ vertical
}: {
groups: ToolOptionGroup[];
+ vertical?: boolean;
}) {
return (
{groups.map((group) => (
-
+
{group.title}
diff --git a/src/pages/tools/string/join/index.tsx b/src/pages/tools/string/join/index.tsx
index 571164a..79b7748 100644
--- a/src/pages/tools/string/join/index.tsx
+++ b/src/pages/tools/string/join/index.tsx
@@ -1,5 +1,5 @@
import { Box } from '@mui/material';
-import React, { useState } from 'react';
+import React, { useRef, useState } from 'react';
import * as Yup from 'yup';
import ToolTextInput from '@components/input/ToolTextInput';
import ToolTextResult from '@components/result/ToolTextResult';
@@ -12,13 +12,14 @@ import ToolInputAndResult from '@components/ToolInputAndResult';
import ToolInfo from '@components/ToolInfo';
import Separator from '@components/Separator';
import Examples from '@components/examples/Examples';
+import { FormikProps } from 'formik';
const initialValues = {
joinCharacter: '',
deleteBlank: true,
deleteTrailing: true
};
-
+type InitialValuesType = typeof initialValues;
const validationSchema = Yup.object().shape({
joinCharacter: Yup.string().required('Join character is required'),
deleteBlank: Yup.boolean().required('Delete blank is required'),
@@ -29,13 +30,13 @@ const mergeOptions = {
placeholder: 'Join Character',
description:
'Symbol that connects broken\n' + 'pieces of text. (Space by default.)\n',
- accessor: 'joinCharacter' as keyof typeof initialValues
+ accessor: 'joinCharacter' as keyof InitialValuesType
};
const blankTrailingOptions: {
title: string;
description: string;
- accessor: keyof typeof initialValues;
+ accessor: keyof InitialValuesType;
}[] = [
{
title: 'Delete Blank Lines',
@@ -62,7 +63,7 @@ feed the cat
make dinner
build a rocket ship and fly away`,
sampleResult: `clean the house and go shopping and feed the cat and make dinner and build a rocket ship and fly away`,
- requiredOptions: {
+ sampleOptions: {
joinCharacter: 'and',
deleteBlank: true,
deleteTrailing: true
@@ -78,7 +79,7 @@ processor
mouse
keyboard`,
sampleResult: `computer, memory, processor, mouse, keyboard`,
- requiredOptions: {
+ sampleOptions: {
joinCharacter: ',',
deleteBlank: false,
deleteTrailing: false
@@ -101,7 +102,7 @@ u
s
!`,
sampleResult: `Textabulous!`,
- requiredOptions: {
+ sampleOptions: {
joinCharacter: '',
deleteBlank: false,
deleteTrailing: false
@@ -112,15 +113,14 @@ s
export default function JoinText() {
const [input, setInput] = useState('');
const [result, setResult] = useState('');
-
- const compute = (optionsValues: typeof initialValues, input: any) => {
+ const optionsFormRef = useRef>(null);
+ const compute = (optionsValues: InitialValuesType, input: any) => {
const { joinCharacter, deleteBlank, deleteTrailing } = optionsValues;
setResult(mergeText(input, deleteBlank, deleteTrailing, joinCharacter));
};
- function changeInputResult(input: string, result: string) {
- setInput(input);
- setResult(result);
+ function changeInputResult(newOptions: InitialValuesType) {
+ optionsFormRef.current?.setValues(newOptions);
const toolsElement = document.getElementById('tool');
if (toolsElement) {
@@ -128,7 +128,7 @@ export default function JoinText() {
}
}
- const getGroups: GetGroupsType = ({
+ const getGroups: GetGroupsType = ({
values,
updateField
}) => [
@@ -169,6 +169,7 @@ export default function JoinText() {
result={}
/>
({
- ...card,
- changeInputResult,
- getGroups
- }))}
+ exampleCards={exampleCards}
getGroups={getGroups}
changeInputResult={changeInputResult}
/>