diff --git a/Unbinder/.storybook/main.ts b/Unbinder/.storybook/main.ts new file mode 100644 index 0000000..8b5fbd2 --- /dev/null +++ b/Unbinder/.storybook/main.ts @@ -0,0 +1,57 @@ +import type { StorybookConfig } from "@storybook/html-webpack5"; +import path from 'path'; +import postcss from 'postcss'; +import tailwindcss from 'tailwindcss'; +import autoprefixer from 'autoprefixer'; + +const config: StorybookConfig = { + stories: [ + "../wwwroot/ts/stories/**/*.mdx", + "../wwwroot/ts/stories/ui/**/*.stories.@(js|jsx|mjs|ts|tsx)", + ], + addons: [ + "@storybook/addon-links", + "@storybook/addon-essentials", + "@storybook/addon-interactions", + { + name: "@storybook/addon-postcss", + options: { + cssLoaderOptions: { + importLoaders: 1 + }, + postcssLoaderOptions: { + implementation: postcss + } + } + } + ], + webpackFinal: async (config) => { + if (!config.module || !config.module.rules) { + throw new Error("Encountered an error during webpack configuration\nAt .storybook/main.ts\nAt webpackFinal"); + } + + config.module.rules.push({ + test: /\.css$/, + use: [{ + loader: 'postcss-loader', + options: { + postcssOptions: { plugins: [tailwindcss, autoprefixer] } + } + }], + include: path.resolve(__dirname, '../') + }) + return config; + }, + framework: { + name: "@storybook/html-webpack5", + options: { + builder: { + useSWC: true, + }, + }, + }, + docs: { + autodocs: "tag", + }, +}; +export default config; diff --git a/Unbinder/.storybook/preview.ts b/Unbinder/.storybook/preview.ts new file mode 100644 index 0000000..c4d3def --- /dev/null +++ b/Unbinder/.storybook/preview.ts @@ -0,0 +1,16 @@ +import type { Preview } from "@storybook/html"; +import "../wwwroot/lib/tailwind.css"; + +const preview: Preview = { + parameters: { + actions: { argTypesRegex: "^on[A-Z].*" }, + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/i, + }, + }, + }, +}; + +export default preview; diff --git a/Unbinder/BuildTools/build.ps1 b/Unbinder/BuildTools/build.ps1 index 3a13edc..d66c62e 100644 --- a/Unbinder/BuildTools/build.ps1 +++ b/Unbinder/BuildTools/build.ps1 @@ -1,2 +1,61 @@ -npm run build -docker compose build \ No newline at end of file +function RebuildJS { + echo "Rebuilding JS..." + + # check for node modules + if (!(Test-Path ./node_modules)) { + echo "Installing node modules..." + npm install + } + + # delete old JS files if they exist + if (Test-Path ./wwwroot/js) { + echo "Removing old build files..." + ri -r -fo ./wwwroot/js + } + + echo "Compiling..." + npx tsc + + echo "Adjusting import statements..." + + # find import statements based on regex and append ".js" file ending to each + $regex = "import\s+.*\s+from\s+['""](.*)['""]" + + $files = Get-ChildItem -Path ./wwwroot/js -Recurse -Include *.js -File + $adjustedFiles = 0 + + foreach ($file in $files) { + $content = Get-Content $file.FullName + $importMatches = $content | Select-String -Pattern $regex -AllMatches + + $adjustedFiles += $importMatches.Matches.Count + + foreach ($match in $importMatches.Matches) { + $import = $match.Groups[1].Value + $newImport = $import + ".js" + $content = $content -replace $import, $newImport + } + + $content | Set-Content $file.FullName + } + + echo "Adjusted $adjustedFiles import statements." +} + +function BuildStorybook { + echo "Building Storybook..." + npm run build-storybook +} + + +# option for only compiling JS +if ($args[0] -eq "-js") { + RebuildJS + echo "Done." +# run full build +} else { + RebuildJS + BuildStorybook + # to do: include Docker? + echo "Done." +} diff --git a/Unbinder/BuildTools/build.sh b/Unbinder/BuildTools/build.sh deleted file mode 100644 index 3a13edc..0000000 --- a/Unbinder/BuildTools/build.sh +++ /dev/null @@ -1,2 +0,0 @@ -npm run build -docker compose build \ No newline at end of file diff --git a/Unbinder/Unbinder.csproj b/Unbinder/Unbinder.csproj index 5f7ae34..e2e22b5 100644 --- a/Unbinder/Unbinder.csproj +++ b/Unbinder/Unbinder.csproj @@ -26,7 +26,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Unbinder/Views/Shared/_Layout.cshtml b/Unbinder/Views/Shared/_Layout.cshtml index 74fa64a..d17b2bd 100644 --- a/Unbinder/Views/Shared/_Layout.cshtml +++ b/Unbinder/Views/Shared/_Layout.cshtml @@ -14,5 +14,5 @@ - @RenderSection("Scripts", required: true) + @RenderSection("Scripts", required: false) diff --git a/Unbinder/Views/Shared/_Navbar.cshtml b/Unbinder/Views/Shared/_Navbar.cshtml index 049f653..e98355e 100644 --- a/Unbinder/Views/Shared/_Navbar.cshtml +++ b/Unbinder/Views/Shared/_Navbar.cshtml @@ -16,4 +16,11 @@ Search My Recipes - \ No newline at end of file + + + +@section Scripts { + +} diff --git a/Unbinder/package.json b/Unbinder/package.json index 9de1065..c6071eb 100644 --- a/Unbinder/package.json +++ b/Unbinder/package.json @@ -4,12 +4,28 @@ "description": "", "main": "wwwroot/js/index.js", "scripts": { - "build": "webpack", - "test": "echo \"Error: no test specified\" && exit 1" + "build": "Powershell.exe .\\BuildTools\\build.ps1", + "build:js": "Powershell.exe .\\BuildTools\\build.ps1 -js", + "test": "echo \"Error: no test specified\" && exit 1", + "storybook": "storybook dev -p 6006", + "build-storybook": "storybook build" }, "author": "Mikayla Dobson", "license": "ISC", "devDependencies": { + "@storybook/addon-essentials": "^7.6.3", + "@storybook/addon-interactions": "^7.6.3", + "@storybook/addon-links": "^7.6.3", + "@storybook/addon-postcss": "^2.0.0", + "@storybook/blocks": "^7.6.3", + "@storybook/html": "^7.6.3", + "@storybook/html-webpack5": "^7.6.3", + "@storybook/test": "^7.6.3", + "autoprefixer": "^10.4.16", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "storybook": "^7.6.3", + "tailwindcss": "^3.3.6", "ts-loader": "^9.5.1", "typescript": "^5.3.2", "webpack": "^5.89.0", diff --git a/Unbinder/tsconfig.json b/Unbinder/tsconfig.json index 0a24e99..8192e97 100644 --- a/Unbinder/tsconfig.json +++ b/Unbinder/tsconfig.json @@ -5,9 +5,11 @@ "removeComments": false, "sourceMap": true, "esModuleInterop": true, + "allowSyntheticDefaultImports": true, "moduleResolution": "Bundler", "module": "ESNext", - "target": "ES5", + "target": "ES6", + "rootDir": "wwwroot/ts", "outDir": "wwwroot/js" }, "include": [ @@ -16,5 +18,10 @@ "exclude": [ "node_modules", "wwwroot/js" - ] + ], + "ts-node": { + "compilerOptions": { + "module": "CommonJS" + } + } } diff --git a/Unbinder/webpack.config.js b/Unbinder/webpack.config.js deleted file mode 100644 index f0b470d..0000000 --- a/Unbinder/webpack.config.js +++ /dev/null @@ -1,38 +0,0 @@ -const path = require('path'); -const fs = require('fs'); - -const jsRoot = path.resolve(__dirname, 'wwwroot/js'); - -if (fs.existsSync(jsRoot)) { - fs.rmdirSync(jsRoot, { recursive: true }); -} - -module.exports = { - entry: { - searchRecipes: "./wwwroot/ts/searchRecipes.ts", - createRecipe: "./wwwroot/ts/createRecipe.ts", - "types/validators": "./wwwroot/ts/types/validators.ts", - "types/models": "./wwwroot/ts/types/models.ts", - types: "./wwwroot/ts/types/index.ts", - }, - mode: 'production', - optimization: { - minimize: false, - }, - module: { - rules: [ - { - test: /\.ts$/, - use: 'ts-loader', - exclude: /node_modules/, - }, - ] - }, - resolve: { - extensions: ['.ts', '.js'], - }, - output: { - filename: '[name].js', - path: path.resolve(__dirname, 'wwwroot/js'), - } -} \ No newline at end of file diff --git a/Unbinder/wwwroot/css/site.css b/Unbinder/wwwroot/css/site.css index f27e5ad..30ab421 100644 --- a/Unbinder/wwwroot/css/site.css +++ b/Unbinder/wwwroot/css/site.css @@ -15,4 +15,4 @@ html { body { margin-bottom: 60px; -} \ No newline at end of file +} diff --git a/Unbinder/wwwroot/ts/stories/Configure.mdx b/Unbinder/wwwroot/ts/stories/Configure.mdx new file mode 100644 index 0000000..e4d0058 --- /dev/null +++ b/Unbinder/wwwroot/ts/stories/Configure.mdx @@ -0,0 +1,364 @@ +import { Meta } from "@storybook/blocks"; + +import Github from "./assets/github.svg"; +import Discord from "./assets/discord.svg"; +import Youtube from "./assets/youtube.svg"; +import Tutorials from "./assets/tutorials.svg"; +import Styling from "./assets/styling.png"; +import Context from "./assets/context.png"; +import Assets from "./assets/assets.png"; +import Docs from "./assets/docs.png"; +import Share from "./assets/share.png"; +import FigmaPlugin from "./assets/figma-plugin.png"; +import Testing from "./assets/testing.png"; +import Accessibility from "./assets/accessibility.png"; +import Theming from "./assets/theming.png"; +import AddonLibrary from "./assets/addon-library.png"; + +export const RightArrow = () => + + + + + +
+
+ # Configure your project + + Because Storybook works separately from your app, you'll need to configure it for your specific stack and setup. Below, explore guides for configuring Storybook with popular frameworks and tools. If you get stuck, learn how you can ask for help from our community. +
+
+
+ A wall of logos representing different styling technologies +

Add styling and CSS

+

Like with web applications, there are many ways to include CSS within Storybook. Learn more about setting up styling within Storybook.

+ Learn more +
+
+ An abstraction representing the composition of data for a component +

Provide context and mocking

+

Often when a story doesn't render, it's because your component is expecting a specific environment or context (like a theme provider) to be available.

+ Learn more +
+
+ A representation of typography and image assets +
+

Load assets and resources

+

To link static files (like fonts) to your projects and stories, use the + `staticDirs` configuration option to specify folders to load when + starting Storybook.

+ Learn more +
+
+
+
+
+
+ # Do more with Storybook + + Now that you know the basics, let's explore other parts of Storybook that will improve your experience. This list is just to get you started. You can customise Storybook in many ways to fit your needs. +
+ +
+
+
+ A screenshot showing the autodocs tag being set, pointing a docs page being generated +

Autodocs

+

Auto-generate living, + interactive reference documentation from your components and stories.

+ Learn more +
+
+ A browser window showing a Storybook being published to a chromatic.com URL +

Publish to Chromatic

+

Publish your Storybook to review and collaborate with your entire team.

+ Learn more +
+
+ Windows showing the Storybook plugin in Figma +

Figma Plugin

+

Embed your stories into Figma to cross-reference the design and live + implementation in one place.

+ Learn more +
+
+ Screenshot of tests passing and failing +

Testing

+

Use stories to test a component in all its variations, no matter how + complex.

+ Learn more +
+
+ Screenshot of accessibility tests passing and failing +

Accessibility

+

Automatically test your components for a11y issues as you develop.

+ Learn more +
+
+ Screenshot of Storybook in light and dark mode +

Theming

+

Theme Storybook's UI to personalize it to your project.

+ Learn more +
+
+
+
+
+
+

Addons

+

Integrate your tools with Storybook to connect workflows.

+ Discover all addons +
+
+ Integrate your tools with Storybook to connect workflows. +
+
+ +
+
+ Github logo + Join our contributors building the future of UI development. + + Star on GitHub +
+
+ Discord logo +
+ Get support and chat with frontend developers. + + Join Discord server +
+
+
+ Youtube logo +
+ Watch tutorials, feature previews and interviews. + + Watch on YouTube +
+
+
+ A book +

Follow guided walkthroughs on for key workflows.

+ + Discover tutorials +
+
+ + diff --git a/Unbinder/wwwroot/ts/stories/assets/accessibility.png b/Unbinder/wwwroot/ts/stories/assets/accessibility.png new file mode 100644 index 0000000..6ffe6fe Binary files /dev/null and b/Unbinder/wwwroot/ts/stories/assets/accessibility.png differ diff --git a/Unbinder/wwwroot/ts/stories/assets/accessibility.svg b/Unbinder/wwwroot/ts/stories/assets/accessibility.svg new file mode 100644 index 0000000..a328883 --- /dev/null +++ b/Unbinder/wwwroot/ts/stories/assets/accessibility.svg @@ -0,0 +1,5 @@ + + Accessibility + + + \ No newline at end of file diff --git a/Unbinder/wwwroot/ts/stories/assets/addon-library.png b/Unbinder/wwwroot/ts/stories/assets/addon-library.png new file mode 100644 index 0000000..95deb38 Binary files /dev/null and b/Unbinder/wwwroot/ts/stories/assets/addon-library.png differ diff --git a/Unbinder/wwwroot/ts/stories/assets/assets.png b/Unbinder/wwwroot/ts/stories/assets/assets.png new file mode 100644 index 0000000..cfba681 Binary files /dev/null and b/Unbinder/wwwroot/ts/stories/assets/assets.png differ diff --git a/Unbinder/wwwroot/ts/stories/assets/avif-test-image.avif b/Unbinder/wwwroot/ts/stories/assets/avif-test-image.avif new file mode 100644 index 0000000..530709b Binary files /dev/null and b/Unbinder/wwwroot/ts/stories/assets/avif-test-image.avif differ diff --git a/Unbinder/wwwroot/ts/stories/assets/context.png b/Unbinder/wwwroot/ts/stories/assets/context.png new file mode 100644 index 0000000..e5cd249 Binary files /dev/null and b/Unbinder/wwwroot/ts/stories/assets/context.png differ diff --git a/Unbinder/wwwroot/ts/stories/assets/discord.svg b/Unbinder/wwwroot/ts/stories/assets/discord.svg new file mode 100644 index 0000000..1204df9 --- /dev/null +++ b/Unbinder/wwwroot/ts/stories/assets/discord.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/Unbinder/wwwroot/ts/stories/assets/docs.png b/Unbinder/wwwroot/ts/stories/assets/docs.png new file mode 100644 index 0000000..a749629 Binary files /dev/null and b/Unbinder/wwwroot/ts/stories/assets/docs.png differ diff --git a/Unbinder/wwwroot/ts/stories/assets/figma-plugin.png b/Unbinder/wwwroot/ts/stories/assets/figma-plugin.png new file mode 100644 index 0000000..8f79b08 Binary files /dev/null and b/Unbinder/wwwroot/ts/stories/assets/figma-plugin.png differ diff --git a/Unbinder/wwwroot/ts/stories/assets/github.svg b/Unbinder/wwwroot/ts/stories/assets/github.svg new file mode 100644 index 0000000..158e026 --- /dev/null +++ b/Unbinder/wwwroot/ts/stories/assets/github.svg @@ -0,0 +1,3 @@ + + + diff --git a/Unbinder/wwwroot/ts/stories/assets/share.png b/Unbinder/wwwroot/ts/stories/assets/share.png new file mode 100644 index 0000000..8097a37 Binary files /dev/null and b/Unbinder/wwwroot/ts/stories/assets/share.png differ diff --git a/Unbinder/wwwroot/ts/stories/assets/styling.png b/Unbinder/wwwroot/ts/stories/assets/styling.png new file mode 100644 index 0000000..d341e82 Binary files /dev/null and b/Unbinder/wwwroot/ts/stories/assets/styling.png differ diff --git a/Unbinder/wwwroot/ts/stories/assets/testing.png b/Unbinder/wwwroot/ts/stories/assets/testing.png new file mode 100644 index 0000000..d4ac39a Binary files /dev/null and b/Unbinder/wwwroot/ts/stories/assets/testing.png differ diff --git a/Unbinder/wwwroot/ts/stories/assets/theming.png b/Unbinder/wwwroot/ts/stories/assets/theming.png new file mode 100644 index 0000000..1535eb9 Binary files /dev/null and b/Unbinder/wwwroot/ts/stories/assets/theming.png differ diff --git a/Unbinder/wwwroot/ts/stories/assets/tutorials.svg b/Unbinder/wwwroot/ts/stories/assets/tutorials.svg new file mode 100644 index 0000000..4b2fc7c --- /dev/null +++ b/Unbinder/wwwroot/ts/stories/assets/tutorials.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/Unbinder/wwwroot/ts/stories/assets/youtube.svg b/Unbinder/wwwroot/ts/stories/assets/youtube.svg new file mode 100644 index 0000000..33a3a61 --- /dev/null +++ b/Unbinder/wwwroot/ts/stories/assets/youtube.svg @@ -0,0 +1,4 @@ + + + + diff --git a/Unbinder/wwwroot/ts/stories/index.ts b/Unbinder/wwwroot/ts/stories/index.ts new file mode 100644 index 0000000..1ec9957 --- /dev/null +++ b/Unbinder/wwwroot/ts/stories/index.ts @@ -0,0 +1 @@ +export * from "./ui/button"; diff --git a/Unbinder/wwwroot/ts/stories/ui/button/Button.stories.ts b/Unbinder/wwwroot/ts/stories/ui/button/Button.stories.ts new file mode 100644 index 0000000..dacf8f4 --- /dev/null +++ b/Unbinder/wwwroot/ts/stories/ui/button/Button.stories.ts @@ -0,0 +1,26 @@ +import type { Meta, StoryObj } from "@storybook/html"; +import { ButtonProps, createButton } from "./Button"; + +type StrongMetaType = + Omit, 'title'> & { title: string } | + Omit, 'component'> & { component: NonNullable } + +const meta: StrongMetaType = { + title: "Button", + tags: ['general-ui'], + render: (args) => createButton(args), + argTypes: { + label: { control: 'text' }, + onClick: { action: 'onClick' }, + primary: { control: 'boolean' }, + "asp-action": { control: 'text' }, + "asp-controller": { control: 'text' } + } +}; + +export default meta; +type Story = StoryObj; + +export const Primary: Story = { + args: {} +} diff --git a/Unbinder/wwwroot/ts/stories/ui/button/Button.ts b/Unbinder/wwwroot/ts/stories/ui/button/Button.ts new file mode 100644 index 0000000..1bc333f --- /dev/null +++ b/Unbinder/wwwroot/ts/stories/ui/button/Button.ts @@ -0,0 +1,24 @@ +export interface ButtonProps { + primary?: boolean; + label: string; + 'asp-controller'?: string; + 'asp-action'?: string; + onClick?: () => void; +} + +export function createButton({ + primary = false, + label, + onClick, + ...rest +}: ButtonProps): HTMLElement { + const element = document.createElement("a"); + + element.innerText = label; + element.className = "bg-slate-800 text-white rounded-lg p-2 ml-2 flex flex-col items-center"; + + element.setAttribute("asp-controller", rest["asp-controller"] ?? ""); + element.setAttribute("asp-action", rest["asp-action"] ?? ""); + + return element; +} diff --git a/Unbinder/wwwroot/ts/stories/ui/button/index.ts b/Unbinder/wwwroot/ts/stories/ui/button/index.ts new file mode 100644 index 0000000..de368d8 --- /dev/null +++ b/Unbinder/wwwroot/ts/stories/ui/button/index.ts @@ -0,0 +1,2 @@ +export * from "./Button"; +export * from "./Button.stories";