Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi step form wip #127

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions examples/e-commerce-product-page/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
--color-gray-50: hsl(0, 0%, 95%);
}

html[data-theme="dark"] {
--background-color: #202c37;
}

body {
font-family: "Kumbh Sans", sans-serif;
max-width: 100vw;
Expand Down
24 changes: 24 additions & 0 deletions examples/multi-step-form/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
2 changes: 2 additions & 0 deletions examples/multi-step-form/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
save-exact = true
package-lock = false
23 changes: 23 additions & 0 deletions examples/multi-step-form/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Frontend Mentor Multi Step Form

Here is the implementation in [Bau.js](https://github.com/grucloud/bau) of the [Frontend Mentor Multi Step Form code challenge](https://www.frontendmentor.io/challenges/multistep-form-YVAnSdqQBJ)

## Workflow

Install the dependencies:

```sh
npm install
```

Start a development server:

```sh
npm run dev
```

Build a production version:

```sh
npm run build
```
17 changes: 17 additions & 0 deletions examples/multi-step-form/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link
rel="icon"
type="image/png"
href="./assets/images/favicon-32x32.png"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Multi Step Form | FrontendMentor</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions examples/multi-step-form/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "frontendmentor-multi-step-form",
"private": true,
"version": "0.90.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"devDependencies": {
"typescript": "^5.0.2",
"vite": "^5.2.11"
},
"dependencies": {
"@grucloud/bau": "^0.90.0",
"@grucloud/bau-css": "^0.90.0",
"@grucloud/bau-ui": "^0.90.0"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/multi-step-form/public/assets/images/icon-pro.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions examples/multi-step-form/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createContext, type Context } from "@grucloud/bau-ui/context";
import multiStepForm from "./multiStepForm";

import "./style.css";

const context = createContext();

const app = (context: Context) => {
const { bau } = context;
const { main } = bau.tags;

const MultiStepForm = multiStepForm(context);

return function () {
return main(MultiStepForm());
};
};

const App = app(context);
document.getElementById("app")?.replaceChildren(App());
140 changes: 140 additions & 0 deletions examples/multi-step-form/src/multiStepForm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { type Context } from "@grucloud/bau-ui/context";
import stepYourInfo from "./stepYourInfo";
import stepSelectPlan from "./stepSelectPlan";

export default function (context: Context) {
const { bau, css } = context;
const { article, div, header, ul, li, span } = bau.tags;
const StepYourInfo = stepYourInfo(context);
const StepSelectPlan = stepSelectPlan(context);

const currentStepState = bau.state(1);

const className = css`
border: 1px solid red;
max-width: 1000px;
margin: auto;
display: flex;
justify-content: center;
align-items: stretch;
gap: 0.6rem;
border-radius: 0.6rem;
padding: 1rem;

& header {
border: 1px solid blue;
background-image: url("./assets/images/bg-sidebar-desktop.svg");
background-size: cover;
> ul {
display: flex;
flex-direction: column;
gap: 1rem;
padding: 1rem;
> li {
&.active {
color: red;
}
display: flex;
align-items: center;
gap: 1rem;
color: var(--font-color-inverse);

.step-number {
font-weight: bold;
padding: 1rem;
border: 1px solid white;
border-radius: 100%;
width: 2rem;
height: 2rem;
display: grid;
place-content: center;
}
.step-label {
text-transform: uppercase;
font-size: smaller;
color: var(--font-color-inverse-secondary);
}
.label {
text-transform: uppercase;
font-weight: bold;
}
}
}
}
.content {
border: 1px solid blue;
min-width: 375px;
min-height: 400px;
> ul {
> li {
display: none;
&.active {
display: block;
}
form {
display: flex;
flex-direction: column;
gap: 1rem;
}
}
}
}
`;
const isCurrentIndex = (index: number) => currentStepState.val == index;

const Header = ({ index, label }: any) =>
li(
{ class: () => isCurrentIndex(index) && "active" },
div({ class: "step-number" }, index),
div(
div({ class: "step-label" }, "Step", index),
div({ class: "label" }, label)
)
);

const next = () => {
currentStepState.val++;
};
const previous = () => {
currentStepState.val--;
};

const onsubmitYourInfo = (event: HTMLFormElement) => {
event.preventDefault();
const payload = Object.fromEntries(new FormData(event.currentTarget));
next();
};

const onsubmitAddon = (event) => {
event.preventDefault();
const payload = Object.fromEntries(new FormData(event.currentTarget));
alert(JSON.stringify(payload));
// next();
};

const steps = [
{
label: "Your Info",
Content: () => StepYourInfo({ onsubmit: onsubmitYourInfo }),
},
{
label: "Select Plan",
Content: ({}) => StepSelectPlan({ onsubmit: onsubmitAddon }),
},
];

return () => {
return article(
{ class: className },
header(ul(steps.map(({ label }, index) => Header({ index, label })))),
div(
{ class: "content" },
ul(
steps.map(({ Content, label }, index) =>
li({ class: () => isCurrentIndex(index) && "active" }, Content({}))
)
)
)
);
};
}
18 changes: 18 additions & 0 deletions examples/multi-step-form/src/stepAddOns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { type Context } from "@grucloud/bau-ui/context";

export default function (context: Context) {
const { bau, css } = context;
const { form, h1, button } = bau.tags;

const className = css`
border: 1px solid red;
`;

return ({ onsubmit }) => {
return form(
{ class: className, onsubmit },
h1("Add-Ons"),
button({ type: "submit" }, "Next")
);
};
}
60 changes: 60 additions & 0 deletions examples/multi-step-form/src/stepSelectPlan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { type Context } from "@grucloud/bau-ui/context";

export default function (context: Context) {
const { bau, css } = context;
const {
form,
button,
h1,
p,
input,
footer,
div,
label,
span,
strong,
small,
} = bau.tags;

const className = css`
border: 1px solid red;
.radio-group {
display: flex;
justify-content: space-around;
> label {
border: 1px solid red;
padding: 1rem;
}
}
`;

return ({ onsubmit }: any) => {
return form(
{ class: className, onsubmit },
h1("Select your plan"),
p("You have the option of monthly or yearly billing."),
div(
{ class: "radio-group" },
label(
input({ type: "radio", name: "plan", id: "arcade" }),
p(strong("Arcade")),
p(small("$9/month"))
),
label(
input({ type: "radio", name: "plan", id: "advanced" }),
p(strong("Advanced")),
p(small("$12/month"))
),
label(
input({ type: "radio", name: "plan", id: "pro" }),
p(strong("Pro")),
p(small("$15/month"))
)
),
footer(
button({ type: "button" }, "Go back"),
button({ type: "submit" }, "Next Step")
)
);
};
}
14 changes: 14 additions & 0 deletions examples/multi-step-form/src/stepSummary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { type Context } from "@grucloud/bau-ui/context";

export default function (context: Context) {
const { bau, css } = context;
const { section, h1 } = bau.tags;

const className = css`
border: 1px solid red;
`;

return () => {
return section({ class: className }, h1("SSummary"));
};
}
Loading