Skip to content

Commit

Permalink
✨ - feat: add login template
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvandescheur committed Feb 20, 2024
1 parent c2e07f5 commit 0b2f9b9
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"exports": {
".": "./dist/esm/index.js",
"./components": "./dist/esm/componets/index.js",
"./templates": "./dist/esm/templates/index.js",
"./style": "./dist/esm/index.css"
},
"types": "dist/esm/index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ import "./style/default.scss";

export * from "./components";
export * as components from "./components";

export * from "./templates";
export * as templates from "./templates";
6 changes: 6 additions & 0 deletions src/lib/i18n/compiled/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@
"value": "yes"
}
],
"mm+twj": [
{
"type": 0,
"value": "login"
}
],
"y0k/u3": [
{
"type": 0,
Expand Down
6 changes: 6 additions & 0 deletions src/lib/i18n/compiled/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@
"value": "ja"
}
],
"mm+twj": [
{
"type": 0,
"value": "inloggen"
}
],
"y0k/u3": [
{
"type": 0,
Expand Down
5 changes: 5 additions & 0 deletions src/lib/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"description": "components.Bool: The accessible label when value is truthy",
"originalDefault": "ja"
},
"mm+twj": {
"defaultMessage": "login",
"description": "templates.Login: The login button label",
"originalDefault": "inloggen"
},
"y0k/u3": {
"defaultMessage": "submit",
"description": "components.Form: The submit form label",
Expand Down
5 changes: 5 additions & 0 deletions src/lib/i18n/messages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"description": "components.Bool: The accessible label when value is truthy",
"originalDefault": "ja"
},
"mm+twj": {
"defaultMessage": "inloggen",
"description": "templates.Login: The login button label",
"originalDefault": "inloggen"
},
"y0k/u3": {
"defaultMessage": "verzenden",
"description": "components.Form: The submit form label",
Expand Down
2 changes: 2 additions & 0 deletions src/templates/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Auto-generated file. Do not modify manually.
export * from "./login";
1 change: 1 addition & 0 deletions src/templates/login/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./login";
30 changes: 30 additions & 0 deletions src/templates/login/login.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Meta, StoryObj } from "@storybook/react";

import { Login } from "./login";

const meta = {
title: "Templates/Login",
component: Login,
argTypes: { onSubmit: { action: "onSubmit" } },
} satisfies Meta<typeof Login>;

export default meta;
type Story = StoryObj<typeof meta>;

export const LoginTemplate: Story = {
args: {
autoComplete: "off",
fields: [
{
label: "Gebruikersnaam",
name: "username",
},
{
label: "Wachtwoord",
name: "Password",
},
],
labelSubmit: "Log in",
nonFieldErrors: ["Username or password invalid"],
},
};
51 changes: 51 additions & 0 deletions src/templates/login/login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React from "react";

import {
Body,
Card,
Column,
Container,
Form,
FormProps,
Grid,
Hr,
Logo,
Page,
} from "../../components";
import { ucFirst } from "../../lib/format/string";
import { useIntl } from "../../lib/i18n/useIntl";

export type LoginProps = FormProps;

/**
* Login template
* @constructor
*/
export const Login: React.FC<LoginProps> = ({ labelSubmit, ...formProps }) => {
const intl = useIntl();

const labelLogin = labelSubmit
? labelSubmit
: intl.formatMessage({
description: "templates.Login: The login button label",
defaultMessage: "inloggen",
});

return (
<Page valign="middle">
<Container>
<Grid>
<Column start={5} span={4}>
<Card>
<Body>
<Logo />
<Hr />
<Form labelSubmit={ucFirst(labelLogin)} {...formProps} />
</Body>
</Card>
</Column>
</Grid>
</Container>
</Page>
);
};

0 comments on commit 0b2f9b9

Please sign in to comment.