Skip to content

Commit

Permalink
Merge branch 'main' of github.com:PradaIng/structuraid-desktop into f…
Browse files Browse the repository at this point in the history
…eature/SI-13
  • Loading branch information
juanse1904 committed May 26, 2023
2 parents d16e660 + 38db546 commit 60d5d7a
Show file tree
Hide file tree
Showing 34 changed files with 10,267 additions and 21,120 deletions.
16 changes: 16 additions & 0 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"sourceType": "unambiguous",
"presets": [
[
"@babel/preset-env",
{
"targets": {
"chrome": 100
}
}
],
"@babel/preset-typescript",
"@babel/preset-react"
],
"plugins": []
}
22 changes: 9 additions & 13 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
module.exports = {
"stories": [
"../src/**/*.stories.mdx",
"../src/**/*.stories.@(js|jsx|ts|tsx)"
],
"addons": [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions"
],
"framework": "@storybook/react",
"core": {
"builder": "@storybook/builder-webpack5"
"stories": ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
"addons": ["@storybook/addon-links", "@storybook/addon-essentials", "@storybook/addon-interactions"],
"framework": {
name: "@storybook/react-webpack5",
options: {}
},
docs: {
autodocs: true
}
}
};
30,663 changes: 9,573 additions & 21,090 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"start:preload": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.preload.dev.ts",
"start:renderer": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack serve --config ./.erb/configs/webpack.config.renderer.dev.ts",
"test": "jest",
"storybook": "concurrently \"npm run watch:css\" \"start-storybook -p 6006\"",
"build-storybook": "build-storybook",
"storybook": "concurrently \"npm run watch:css\" \"storybook dev\"",
"build-storybook": "storybook build",
"build:css": "npx tailwindcss -i ./src/renderer/app/app.css -o ./src/renderer/app/tailwind.css",
"watch:css": "npx tailwindcss -i ./src/renderer/app/app.css -o ./src/renderer/app/tailwind.css --watch"
},
Expand Down Expand Up @@ -130,15 +130,17 @@
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/preset-env": "^7.21.5",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.5",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.7",
"@storybook/addon-actions": "^6.5.16",
"@storybook/addon-essentials": "^6.5.16",
"@storybook/addon-interactions": "^6.5.16",
"@storybook/addon-links": "^6.5.16",
"@storybook/builder-webpack5": "^6.5.16",
"@storybook/manager-webpack5": "^6.5.16",
"@storybook/react": "^6.5.16",
"@storybook/testing-library": "^0.0.13",
"@storybook/addon-actions": "^7.0.17",
"@storybook/addon-essentials": "^7.0.17",
"@storybook/addon-interactions": "^7.0.17",
"@storybook/addon-links": "^7.0.17",
"@storybook/react": "^7.0.17",
"@storybook/react-webpack5": "^7.0.17",
"@storybook/testing-library": "^0.1.0",
"@svgr/webpack": "^6.3.1",
"@teamsupercell/typings-for-css-modules-loader": "^2.5.2",
"@testing-library/jest-dom": "^5.16.5",
Expand Down Expand Up @@ -181,7 +183,7 @@
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-storybook": "^0.6.10",
"eslint-plugin-storybook": "^0.6.12",
"file-loader": "^6.2.0",
"fs-lint": "^1.0.1",
"html-webpack-plugin": "^5.5.0",
Expand All @@ -199,6 +201,7 @@
"rimraf": "^3.0.2",
"sass": "^1.54.4",
"sass-loader": "^13.0.2",
"storybook": "^7.0.17",
"style-loader": "^3.3.1",
"tailwindcss": "^3.2.4",
"terser-webpack-plugin": "^5.3.5",
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/atoms/button/button.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- button.stories.mdx -->
{/* button.stories.mdx */}

import { Canvas, Meta, Story } from '@storybook/addon-docs';

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/atoms/input/input.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Input.stories.mdx -->
{/* Input.stories.mdx */}

import { Canvas, Meta, Story } from '@storybook/addon-docs';
import { AlertIcon } from '@primer/octicons-react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Input.stories.mdx -->
{/* Input.stories.mdx */}

import { Canvas, Meta, Story } from '@storybook/addon-docs';
import { COLORS } from '../../../constants'
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/atoms/text/text.stories.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Text.stories.mdx -->
{/* Text.stories.mdx */}

import { Canvas, Meta, Story } from '@storybook/addon-docs';

Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/molecules/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
export { default as Select } from './select';
export { default as RadioGroup } from './radio-group';
export { default as Notification } from './notification';
1 change: 1 addition & 0 deletions src/renderer/components/molecules/notification/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './notification';
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { useState } from 'react'
import { Canvas, Meta, Story } from '@storybook/addon-docs';
import { COLORS } from '../../../constants'

import Notification from './notification';
import { Button } from '../../atoms';

<Meta title="Molecules/Notification" component={Notification} />

export const Template = (args) => {
return (
<div style={{
padding: '30px',
background: args.color === 'dark' ? COLORS.PRIMARY : COLORS.BLUE_WHITE
}}>
<Notification {...args} />
</div>
)
};

# Notification

This is the `Notification` molecule. It can be used to render a notification message on the UI. It can be an error, an alert, a success notification or some information.

## Usage

The `type` and `message` props are required.
Use the `type` prop to specify the notification type. It can be `"error"`, `"warning"`, `"success"` or `"info"`
Use the `message` prop to specify the notification message.

<Canvas>
<Story
name="error"
args={{
type: 'error',
message: 'Error Notification'
}}
>
{Template.bind({})}
</Story>
</Canvas>

<Canvas>
<Story
name="warning"
args={{
type: 'warning',
message: 'Warning Notification'
}}
>
{Template.bind({})}
</Story>
</Canvas>

<Canvas>
<Story
name="success"
args={{
type: 'success',
message: 'Success Notification'
}}
>
{Template.bind({})}
</Story>
</Canvas>

<Canvas>
<Story
name="info"
args={{
type: 'info',
message: 'Info Notification'
}}
>
{Template.bind({})}
</Story>
</Canvas>

### Custom Actions

The `Notification` component can receive `children`, they will be rendered at the right of the message and can be used to define any custom actions that can be performed by the user

export const CustomActionsTemplate = (args) => {
return (
<div style={{
padding: '30px',
background: args.color === 'dark' ? COLORS.PRIMARY : COLORS.BLUE_WHITE
}}>
<Notification {...args}>
<Button
as="secondary"
type="submit"
variant="small"
>
Accept
</Button>
<Button
as="secondary"
type="submit"
variant="small"
>
Deny
</Button>
</Notification>
</div>
)
};

<Canvas>
<Story
name="custom-actions"
args={{
type: 'error',
message: 'Error Notification'
}}
>
{CustomActionsTemplate.bind({})}
</Story>
</Canvas>

### Controlled from Outside

The notification visibility state can be controlled from an outside component using the `open` and `onVisibilityChange` props.

export const ControlledTemplate = (args) => {
const [open, setOpen] = useState(false)
const handleClose = (newOpen) => setOpen(newOpen)
return (
<div style={{
padding: '30px',
background: args.color === 'dark' ? COLORS.PRIMARY : COLORS.BLUE_WHITE
}}>
<Notification {...args} open={open} onVisibilityChange={handleClose} />
<div style={{paddingTop: "20px"}}>
<Button onClick={() => setOpen(!open)}>
Click me
</Button>
</div>
</div>
)
};

<Canvas>
<Story
name="controlled"
args={{
type: 'success',
message: 'Success Notification'
}}
>
{ControlledTemplate.bind({})}
</Story>
</Canvas>
105 changes: 105 additions & 0 deletions src/renderer/components/molecules/notification/notification.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { useState, useEffect } from 'react';
import {
SkipIcon,
AlertIcon,
CheckIcon,
BookmarkIcon,
XIcon,
} from '@primer/octicons-react';
import { Text } from '../../atoms';

import type { NotificationProps } from './types';

const ICON_MAPPER = {
error: SkipIcon,
warning: AlertIcon,
success: CheckIcon,
info: BookmarkIcon,
};

const BG_COLORS_MAPPER = {
error: {
dark: 'bg-notice-dark-red',
base: 'bg-notice-red',
soft: 'bg-notice-soft-red',
},
warning: {
dark: 'bg-notice-yellow',
base: 'bg-notice-yellow',
soft: 'bg-notice-soft-yellow',
},
success: {
dark: 'bg-notice-green',
base: 'bg-notice-green',
soft: 'bg-notice-soft-green',
},
info: {
dark: 'bg-primary',
base: 'bg-secondary',
soft: 'bg-soft-blue',
},
};

const Notification = ({
message,
type,
children,
open: defaultOpen = true,
onVisibilityChange,
}: NotificationProps) => {
const Icon = ICON_MAPPER[type];
const bgColorScheme = BG_COLORS_MAPPER[type];
const [open, setOpen] = useState(defaultOpen);

useEffect(() => {
setOpen(defaultOpen);
}, [defaultOpen]);

const handleClose = () => {
setOpen(false);
if (onVisibilityChange) onVisibilityChange(false);
};

return (
<div
className={`
flex items-center gap-4
transition-all
${bgColorScheme.soft}
${
open ? 'w-full h-12 opacity-100' : 'w-0 h-0 overflow-hidden opacity-0'
}
`}
>
<div
className={`${bgColorScheme.dark} w-12 h-12 flex flex-grow-0 flex-shrink-0 justify-center items-center`}
>
<Icon size={24} className="text-blue-white" />
</div>

<Text
as="body-small-interface"
className="w-full flex-grow-1 flex-shrink-1"
color="primary"
>
{message}
</Text>

{children && (
<div className="flex items-center gap-3 flex-grow-0 flex-shrink-0">
{children}
</div>
)}

<button
type="button"
className="block w-10 h-10 hover:opacity-50 transition-all flex-grow-0 flex-shrink-0"
onClick={handleClose}
>
<XIcon size={16} className="text-primary" />
</button>
</div>
);
};

export default Notification;
Loading

0 comments on commit 60d5d7a

Please sign in to comment.