From 6d2e12811cc144ad98a8600acaa55afd4975e629 Mon Sep 17 00:00:00 2001 From: LasseStaus Date: Tue, 7 May 2024 14:00:03 +0200 Subject: [PATCH] wipw --- base.scss | 1 + package.json | 2 +- .../MaterialSearch.stories.tsx | 20 ++++ .../material-search/MaterialSearch.tsx | 92 +++++++++++++++++++ .../material-search/material-search.scss | 67 ++++++++++++++ 5 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 src/stories/Library/material-search/MaterialSearch.stories.tsx create mode 100644 src/stories/Library/material-search/MaterialSearch.tsx create mode 100644 src/stories/Library/material-search/material-search.scss diff --git a/base.scss b/base.scss index 61051826d..d3d35342b 100644 --- a/base.scss +++ b/base.scss @@ -139,6 +139,7 @@ @import "./src/stories/Library/opening-hours/opening-hours-skeleton"; @import "./src/stories/Library/filtered-event-list/filtered-event-list"; @import "./src/stories/Library/event-list-stacked/event-list-stacked"; +@import "./src/stories/Library/material-search/material-search"; // Autosuggest block styling needs to be loaded before the rest of the scss for autosuggest @import "./src/stories/Blocks/autosuggest/autosuggest"; diff --git a/package.json b/package.json index a077cceac..43cbe8862 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "css:lint": "concurrently 'yarn:css:stylelint' 'yarn:css:prettier -- --check' --raw", "css:lint:watch": "chokidar 'src/**/*.scss' -c 'yarn css:lint'", "css:format": "concurrently 'yarn:css:stylelint -- --fix' 'yarn:css:prettier -- --write' --max-processes 1 --raw", - "css:build": "sass base.scss:src/styles/css/base.css wysiwyg.scss:src/styles/css/wysiwyg.css src/stories/Library/opening-hours-editor/opening-hours-editor.scss:src/styles/css/opening-hours-editor.css --style compressed", + "css:build": "sass base.scss:src/styles/css/base.css wysiwyg.scss:src/styles/css/wysiwyg.css src/stories/Library/opening-hours-editor/opening-hours-editor.scss:src/styles/css/opening-hours-editor.css src/stories/Library/material-search/material-search.scss:src/styles/css/material-search.css --style compressed", "css:watch": "yarn css:build -- --watch", "build": "concurrently 'yarn:css:build' --raw", "markdown:lint": "markdownlint-cli2", diff --git a/src/stories/Library/material-search/MaterialSearch.stories.tsx b/src/stories/Library/material-search/MaterialSearch.stories.tsx new file mode 100644 index 000000000..725bf7759 --- /dev/null +++ b/src/stories/Library/material-search/MaterialSearch.stories.tsx @@ -0,0 +1,20 @@ +import { ComponentMeta, ComponentStory } from "@storybook/react"; + +import MaterialSearch from "./MaterialSearch"; + +export default { + title: "Library / Find Mig Igen", + component: MaterialSearch, + argTypes: { + workId: { + defaultValue: "1", + type: "string", + }, + }, +} as ComponentMeta; + +const Template: ComponentStory = (args) => ( + +); + +export const Default = Template.bind({}); diff --git a/src/stories/Library/material-search/MaterialSearch.tsx b/src/stories/Library/material-search/MaterialSearch.tsx new file mode 100644 index 000000000..d1f49afc8 --- /dev/null +++ b/src/stories/Library/material-search/MaterialSearch.tsx @@ -0,0 +1,92 @@ +import { FC, ChangeEvent, useState, useEffect } from "react"; +import clsx from "clsx"; +// Define the props type for the MaterialSearch component +type MaterialSearchProps = { + workId: string; +}; + +// Functional component using the FC type from React with defined props +const MaterialSearch: FC = ({ workId }) => { + // Handler for changes in the search input + + const [fieldWorkId, setFieldWorkId] = useState(null); + const [fieldMaterialTypeId, setFieldMaterialTypeId] = useState( + null + ); + + useEffect(() => { + setFieldWorkId(Math.floor(Math.random() * 1000)); + setFieldMaterialTypeId(Math.floor(Math.random() * 1000)); + }, []); + + const handleSearch = (e: ChangeEvent) => { + const SearchInputValue = e.target.value; + const hiddenFieldWorkId = document.querySelector( + `#material-search__field-work-id--${fieldWorkId}` + ); + const hiddenFieldMaterialTypeId = document.querySelector( + `#material-search__field-material-type-id--${fieldMaterialTypeId}` + ); + + if (hiddenFieldWorkId) { + hiddenFieldWorkId.setAttribute("value", SearchInputValue); + } + console.log("Searching for:", SearchInputValue); + }; + + return ( +
+
+
Work ID for testing: {workId}
+ + +
+ + + + +
+ ); +}; + +export default MaterialSearch; diff --git a/src/stories/Library/material-search/material-search.scss b/src/stories/Library/material-search/material-search.scss new file mode 100644 index 000000000..1e1cedf47 --- /dev/null +++ b/src/stories/Library/material-search/material-search.scss @@ -0,0 +1,67 @@ +$_gin_border_color: #8e929c; +@import "../../../styles/scss/tools/variables.spacings.scss"; +@import "../../../styles/scss/tools/variables.colors.scss"; + +.material-search { + margin: auto; + padding: 2rem; + border: 1px solid black; + border-radius: 10px; + max-width: 550px; +} + +.material-search__label { + display: flex; + flex-direction: column; + gap: $s-md; + + margin-bottom: $s-lg; +} + +.material-search__hidden-inputs { + margin-bottom: $s-xl; +} + +.material-search__inputs-container { + display: grid; + grid-template-columns: 2fr 1fr; + gap: $s-md; +} + +.material-search__preview { + display: grid; + min-height: 150px; + color: $color__global-grey; + cursor: not-allowed; + + border: 1px solid $_gin_border_color; + border-radius: 5px; + overflow: hidden; +} +.material-search__preview-placeholder { + height: 100%; + background-color: $color__global-tertiary-1; +} +.material-search__preview-material-content { + display: grid; +} +.material-search__preview-material { + background-color: white; + + display: flex; + gap: $s-md; + padding: $s-md; + align-items: center; +} + +.material-search__input, +.material-search__selector { + border: 1px solid $_gin_border_color; + padding: 0.5rem; + border-radius: 0.5rem; + height: 100%; + font-family: inherit; + &:disabled { + background-color: $color__global-tertiary-1; + } +}