@pautena/react-design-system 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/package.json +1 -1
  2. package/.eslintrc.js +0 -26
  3. package/.github/workflows/ci.yml +0 -23
  4. package/.github/workflows/deploy-storybook.yaml +0 -23
  5. package/.github/workflows/publish.yml +0 -31
  6. package/.husky/pre-commit +0 -5
  7. package/.prettierignore +0 -5
  8. package/.storybook/main.js +0 -10
  9. package/.storybook/preview.js +0 -36
  10. package/babel.config.js +0 -13
  11. package/jest.config.js +0 -17
  12. package/jest.setup.ts +0 -5
  13. package/rollup.config.js +0 -52
  14. package/src/components/app-bar/app-bar.stories.tsx +0 -54
  15. package/src/components/app-bar/app-bar.test.tsx +0 -142
  16. package/src/components/app-bar/app-bar.tsx +0 -150
  17. package/src/components/app-bar/app-bar.types.ts +0 -17
  18. package/src/components/app-bar/index.ts +0 -3
  19. package/src/components/app-bar/mini-app-bar/index.ts +0 -1
  20. package/src/components/app-bar/mini-app-bar/mini-app-bar.tsx +0 -31
  21. package/src/components/bullet/bullet.stories.tsx +0 -43
  22. package/src/components/bullet/bullet.test.tsx +0 -24
  23. package/src/components/bullet/bullet.tsx +0 -30
  24. package/src/components/bullet/index.ts +0 -1
  25. package/src/components/center-container/center-container.stories.tsx +0 -50
  26. package/src/components/center-container/center-container.test.tsx +0 -16
  27. package/src/components/center-container/center-container.tsx +0 -32
  28. package/src/components/center-container/index.ts +0 -1
  29. package/src/components/content/content.stories.tsx +0 -23
  30. package/src/components/content/content.test.tsx +0 -26
  31. package/src/components/content/content.tsx +0 -11
  32. package/src/components/content/content.types.ts +0 -5
  33. package/src/components/content/index.ts +0 -2
  34. package/src/components/drawer/__snapshots__/drawer.test.tsx.snap +0 -20
  35. package/src/components/drawer/drawer.context.ts +0 -20
  36. package/src/components/drawer/drawer.mixins.ts +0 -24
  37. package/src/components/drawer/drawer.mock.tsx +0 -100
  38. package/src/components/drawer/drawer.provider.tsx +0 -23
  39. package/src/components/drawer/drawer.test.tsx +0 -97
  40. package/src/components/drawer/drawer.tsx +0 -30
  41. package/src/components/drawer/drawer.types.ts +0 -53
  42. package/src/components/drawer/index.ts +0 -5
  43. package/src/components/drawer/mini-drawer/index.ts +0 -1
  44. package/src/components/drawer/mini-drawer/mini-drawer.stories.tsx +0 -34
  45. package/src/components/drawer/mini-drawer/mini-drawer.tsx +0 -67
  46. package/src/components/drawer-content/drawer-content.stories.tsx +0 -29
  47. package/src/components/drawer-content/drawer-content.test.tsx +0 -34
  48. package/src/components/drawer-content/drawer-content.tsx +0 -18
  49. package/src/components/drawer-content/index.ts +0 -1
  50. package/src/components/drawer-item/drawer-item.stories.tsx +0 -62
  51. package/src/components/drawer-item/drawer-item.test.tsx +0 -119
  52. package/src/components/drawer-item/drawer-item.tsx +0 -71
  53. package/src/components/drawer-item/index.ts +0 -1
  54. package/src/components/drawer-section/drawer-section.mock.tsx +0 -39
  55. package/src/components/drawer-section/drawer-section.stories.tsx +0 -28
  56. package/src/components/drawer-section/drawer-section.test.tsx +0 -44
  57. package/src/components/drawer-section/drawer-section.tsx +0 -40
  58. package/src/components/drawer-section/index.ts +0 -1
  59. package/src/components/header/header.dummy.ts +0 -55
  60. package/src/components/header/header.stories.tsx +0 -116
  61. package/src/components/header/header.test.tsx +0 -169
  62. package/src/components/header/header.tsx +0 -121
  63. package/src/components/header/header.types.ts +0 -61
  64. package/src/components/header/index.ts +0 -2
  65. package/src/components/index.ts +0 -18
  66. package/src/components/label/index.ts +0 -1
  67. package/src/components/label/label.stories.tsx +0 -49
  68. package/src/components/label/label.test.tsx +0 -30
  69. package/src/components/label/label.tsx +0 -60
  70. package/src/components/link/index.ts +0 -1
  71. package/src/components/link/link.tsx +0 -17
  72. package/src/components/loading-area/index.ts +0 -1
  73. package/src/components/loading-area/loading-area.stories.tsx +0 -17
  74. package/src/components/loading-area/loading-area.test.tsx +0 -11
  75. package/src/components/loading-area/loading-area.tsx +0 -13
  76. package/src/components/placeholder/index.ts +0 -1
  77. package/src/components/placeholder/placeholder.mock.ts +0 -15
  78. package/src/components/placeholder/placeholder.stories.tsx +0 -44
  79. package/src/components/placeholder/placeholder.test.tsx +0 -76
  80. package/src/components/placeholder/placeholder.tsx +0 -75
  81. package/src/components/query-container/index.ts +0 -1
  82. package/src/components/query-container/query-container.stories.tsx +0 -68
  83. package/src/components/query-container/query-container.test.tsx +0 -95
  84. package/src/components/query-container/query-container.tsx +0 -71
  85. package/src/components/sign-in/index.ts +0 -1
  86. package/src/components/sign-in/sign-in.stories.tsx +0 -36
  87. package/src/components/sign-in/sign-in.test.tsx +0 -95
  88. package/src/components/sign-in/sign-in.tsx +0 -97
  89. package/src/components/tab/index.ts +0 -2
  90. package/src/components/tab/tab-card/index.ts +0 -1
  91. package/src/components/tab/tab-card/tab-card.dummy.tsx +0 -30
  92. package/src/components/tab/tab-card/tab-card.stories.tsx +0 -22
  93. package/src/components/tab/tab-card/tab-card.test.tsx +0 -53
  94. package/src/components/tab/tab-card/tab-card.tsx +0 -27
  95. package/src/components/tab/tab-panel/index.ts +0 -1
  96. package/src/components/tab/tab-panel/tab-panel.test.tsx +0 -26
  97. package/src/components/tab/tab-panel/tab-panel.tsx +0 -27
  98. package/src/components/table/enhanced-remote-table/enhanced-remote-table.mock.tsx +0 -27
  99. package/src/components/table/enhanced-remote-table/enhanced-remote-table.stories.tsx +0 -24
  100. package/src/components/table/enhanced-remote-table/enhanced-remote-table.test.tsx +0 -77
  101. package/src/components/table/enhanced-remote-table/enhanced-remote-table.tsx +0 -74
  102. package/src/components/table/enhanced-remote-table/index.ts +0 -1
  103. package/src/components/table/enhanced-table/enhanced-table-head.tsx +0 -58
  104. package/src/components/table/enhanced-table/enhanced-table.mock.tsx +0 -93
  105. package/src/components/table/enhanced-table/enhanced-table.stories.tsx +0 -21
  106. package/src/components/table/enhanced-table/enhanced-table.test.tsx +0 -107
  107. package/src/components/table/enhanced-table/enhanced-table.tsx +0 -136
  108. package/src/components/table/enhanced-table/index.ts +0 -2
  109. package/src/components/table/index.ts +0 -2
  110. package/src/components/table-list/index.ts +0 -1
  111. package/src/components/table-list/table-list.stories.tsx +0 -75
  112. package/src/components/table-list/table-list.test.tsx +0 -284
  113. package/src/components/table-list/table-list.tsx +0 -127
  114. package/src/components/value-displays/group-value-card/group-value-card.mock.tsx +0 -35
  115. package/src/components/value-displays/group-value-card/group-value-card.stories.tsx +0 -26
  116. package/src/components/value-displays/group-value-card/group-value-card.test.tsx +0 -58
  117. package/src/components/value-displays/group-value-card/group-value-card.tsx +0 -63
  118. package/src/components/value-displays/group-value-card/index.ts +0 -1
  119. package/src/components/value-displays/index.ts +0 -4
  120. package/src/components/value-displays/value-boolean/index.ts +0 -1
  121. package/src/components/value-displays/value-boolean/value-boolean.stories.tsx +0 -25
  122. package/src/components/value-displays/value-boolean/value-boolean.test.tsx +0 -27
  123. package/src/components/value-displays/value-boolean/value-boolean.tsx +0 -33
  124. package/src/components/value-displays/value-card/index.ts +0 -1
  125. package/src/components/value-displays/value-card/value-card.stories.tsx +0 -22
  126. package/src/components/value-displays/value-card/value-card.test.tsx +0 -18
  127. package/src/components/value-displays/value-card/value-card.tsx +0 -12
  128. package/src/components/value-displays/value-text/index.ts +0 -1
  129. package/src/components/value-displays/value-text/value-test.test.tsx +0 -21
  130. package/src/components/value-displays/value-text/value-text.stories.tsx +0 -26
  131. package/src/components/value-displays/value-text/value-text.tsx +0 -32
  132. package/src/generators/generators.mock.ts +0 -238
  133. package/src/generators/generators.model.ts +0 -46
  134. package/src/generators/index.ts +0 -4
  135. package/src/generators/model-form/index.ts +0 -1
  136. package/src/generators/model-form/model-form.stories.tsx +0 -30
  137. package/src/generators/model-form/model-form.test.tsx +0 -100
  138. package/src/generators/model-form/model-form.tsx +0 -97
  139. package/src/generators/model-router/index.ts +0 -1
  140. package/src/generators/model-router/model-router.test.tsx +0 -666
  141. package/src/generators/model-router/model-router.tsx +0 -29
  142. package/src/generators/model-router/model-router.types.ts +0 -14
  143. package/src/generators/model-router/screens/add-screen.tsx +0 -69
  144. package/src/generators/model-router/screens/details-screen.tsx +0 -62
  145. package/src/generators/model-router/screens/index.ts +0 -4
  146. package/src/generators/model-router/screens/list-screen.tsx +0 -110
  147. package/src/generators/model-router/screens/screens.types.ts +0 -13
  148. package/src/generators/model-router/screens/update-screen.tsx +0 -96
  149. package/src/generators/model-router/stories/details-screen.stories.tsx +0 -38
  150. package/src/generators/model-router/stories/list-screen.stories.tsx +0 -45
  151. package/src/generators/model-router/stories/model-router.stories.tsx +0 -164
  152. package/src/generators/model-router/stories/templates.tsx +0 -39
  153. package/src/generators/object-details/index.ts +0 -1
  154. package/src/generators/object-details/object-details.stories.tsx +0 -20
  155. package/src/generators/object-details/object-details.test.tsx +0 -21
  156. package/src/generators/object-details/object-details.tsx +0 -76
  157. package/src/index.ts +0 -4
  158. package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.stories.tsx +0 -28
  159. package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.test.tsx +0 -30
  160. package/src/layouts/app-bar-with-drawer-layout/app-bar-with-drawer-layout.tsx +0 -37
  161. package/src/layouts/app-bar-with-drawer-layout/index.ts +0 -1
  162. package/src/layouts/header-layout/header-layout.stories.tsx +0 -204
  163. package/src/layouts/header-layout/header-layout.test.tsx +0 -37
  164. package/src/layouts/header-layout/header-layout.tsx +0 -23
  165. package/src/layouts/header-layout/index.ts +0 -1
  166. package/src/layouts/index.ts +0 -2
  167. package/src/providers/index.ts +0 -2
  168. package/src/providers/notification-center/index.ts +0 -2
  169. package/src/providers/notification-center/notification-center.context.ts +0 -37
  170. package/src/providers/notification-center/notification-center.provider.tsx +0 -51
  171. package/src/providers/notification-center/notification-center.stories.tsx +0 -52
  172. package/src/providers/notification-center/notification-center.test.tsx +0 -112
  173. package/src/providers/tab-provider/index.ts +0 -2
  174. package/src/providers/tab-provider/tab-provider.context.ts +0 -8
  175. package/src/providers/tab-provider/tab-provider.provider.tsx +0 -13
  176. package/src/storybook.tsx +0 -90
  177. package/src/tests/assertions.ts +0 -76
  178. package/src/tests/components.tsx +0 -60
  179. package/src/tests/content-placeholder.stories.tsx +0 -16
  180. package/src/tests/index.ts +0 -3
  181. package/src/tests/skeleton-card.stories.tsx +0 -18
  182. package/src/tests/testing-library.tsx +0 -65
  183. package/src/utils/arrays.test.ts +0 -9
  184. package/src/utils/arrays.ts +0 -7
  185. package/src/utils/index.ts +0 -2
  186. package/src/utils/theme.ts +0 -11
  187. package/tsconfig.json +0 -25
  188. package/tsconfig.rollup.json +0 -28
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pautena/react-design-system",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "My custom design system on top of MUI",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
package/.eslintrc.js DELETED
@@ -1,26 +0,0 @@
1
- module.exports = {
2
- env: {
3
- browser: true,
4
- es2021: true,
5
- node: true,
6
- },
7
- extends: [
8
- "eslint:recommended",
9
- "plugin:react/recommended",
10
- "plugin:@typescript-eslint/recommended",
11
- "plugin:prettier/recommended",
12
- ],
13
- parser: "@typescript-eslint/parser",
14
- parserOptions: {
15
- ecmaFeatures: {
16
- jsx: true,
17
- },
18
- ecmaVersion: "latest",
19
- sourceType: "module",
20
- },
21
- plugins: ["react", "@typescript-eslint"],
22
- rules: {
23
- "prettier/prettier": "error",
24
- "react/display-name": "off",
25
- },
26
- };
@@ -1,23 +0,0 @@
1
- name: 'ci'
2
- on:
3
- pull_request:
4
- push:
5
- branches:
6
- - main
7
-
8
- jobs:
9
- ci:
10
- runs-on: ubuntu-latest
11
- steps:
12
- - uses: actions/checkout@v2
13
- - uses: actions/cache@v2
14
- with:
15
- path: |
16
- ${{ steps.yarn-cache-dir-path.outputs.dir }}
17
- '**/node_modules'
18
- key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
19
- restore-keys: |
20
- ${{ runner.os }}-yarn-
21
- - run: yarn
22
- - run: yarn lint
23
- - run: yarn test
@@ -1,23 +0,0 @@
1
- name: 'Deploy Storybook'
2
- on:
3
- push:
4
- branches:
5
- - main
6
-
7
- jobs:
8
- ci:
9
- runs-on: ubuntu-latest
10
- steps:
11
- - uses: actions/checkout@v2
12
- - uses: actions/cache@v2
13
- id: yarn-cache
14
- with:
15
- path: '**/node_modules'
16
- key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
17
- - run: yarn
18
- - run: yarn storybook:build
19
- - name: Deploy
20
- uses: peaceiris/actions-gh-pages@v3
21
- with:
22
- github_token: ${{ secrets.GITHUB_TOKEN }}
23
- publish_dir: ./storybook-static
@@ -1,31 +0,0 @@
1
- name: Publish to NPM
2
- on:
3
- release:
4
- types: [created]
5
- jobs:
6
- build:
7
- runs-on: ubuntu-latest
8
- steps:
9
- - name: Checkout
10
- uses: actions/checkout@v2
11
- - uses: actions/cache@v2
12
- with:
13
- path: |
14
- ${{ steps.yarn-cache-dir-path.outputs.dir }}
15
- '**/node_modules'
16
- key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
17
- restore-keys: |
18
- ${{ runner.os }}-yarn-
19
- - name: Setup Node
20
- uses: actions/setup-node@v2
21
- with:
22
- node-version: '16.x'
23
- registry-url: 'https://registry.npmjs.org'
24
- - name: Install dependencies
25
- run: yarn install
26
- - name: Build
27
- run: yarn build
28
- - name: Publish package on NPM
29
- run: npm publish --access public
30
- env:
31
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/.husky/pre-commit DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname -- "$0")/_/husky.sh"
3
-
4
- yarn lint
5
- yarn test
package/.prettierignore DELETED
@@ -1,5 +0,0 @@
1
- node_modules
2
- storybook-static
3
- coverage
4
- dist
5
- types
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
3
- addons: [
4
- "@storybook/addon-links",
5
- "@storybook/addon-essentials",
6
- "@storybook/addon-interactions",
7
- "@storybook/addon-knobs",
8
- ],
9
- framework: "@storybook/react",
10
- };
@@ -1,36 +0,0 @@
1
- import { ThemeProvider, CssBaseline, createTheme } from "@mui/material";
2
- import { addDecorator } from "@storybook/react";
3
- import { Box } from "@mui/material";
4
- import { select, withKnobs } from "@storybook/addon-knobs";
5
-
6
- const light = createTheme();
7
- const dark = createTheme({
8
- palette: {
9
- mode: "dark",
10
- },
11
- });
12
-
13
- const themes = { light, dark };
14
- const themeNames = Object.keys(themes);
15
-
16
- addDecorator((Story) => {
17
- const theme = select("Theme", themeNames, themeNames[0], "Themes");
18
-
19
- return (
20
- <ThemeProvider theme={themes[theme]}>
21
- <CssBaseline />
22
- <Story />
23
- </ThemeProvider>
24
- );
25
- });
26
- addDecorator(withKnobs);
27
-
28
- export const parameters = {
29
- actions: { argTypesRegex: "^on[A-Z].*" },
30
- controls: {
31
- matchers: {
32
- color: /(background|color)$/i,
33
- date: /Date$/,
34
- },
35
- },
36
- };
package/babel.config.js DELETED
@@ -1,13 +0,0 @@
1
- module.exports = {
2
- presets: ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"],
3
- plugins: [
4
- [
5
- "module-resolver",
6
- {
7
- alias: {
8
- "~": "./src",
9
- },
10
- },
11
- ],
12
- ],
13
- };
package/jest.config.js DELETED
@@ -1,17 +0,0 @@
1
- module.exports = {
2
- testEnvironment: "jsdom",
3
- setupFilesAfterEnv: ["./jest.setup.ts"],
4
- collectCoverageFrom: [
5
- "./src/**",
6
- "!src/**/*.stories.tsx",
7
- "!src/**/*.dummy.ts",
8
- "!src/**/*.mock.tsx",
9
- "!src/**/*.test.tsx",
10
- "!src/storybook.tsx",
11
- "!src/tests/**",
12
- "!src/**/__snapshots__/**",
13
- ],
14
- moduleNameMapper: {
15
- "~/(.*)": "<rootDir>/src/$1",
16
- },
17
- };
package/jest.setup.ts DELETED
@@ -1,5 +0,0 @@
1
- import "@testing-library/jest-dom";
2
-
3
- beforeEach(() => {
4
- jest.resetAllMocks();
5
- });
package/rollup.config.js DELETED
@@ -1,52 +0,0 @@
1
- import resolve from "@rollup/plugin-node-resolve";
2
- import commonjs from "@rollup/plugin-commonjs";
3
- import typescript from "@rollup/plugin-typescript";
4
- import alias from "@rollup/plugin-alias";
5
- import dts from "rollup-plugin-dts";
6
- import path from "path";
7
- import { terser } from "rollup-plugin-terser";
8
- import peerDepsExternal from "rollup-plugin-peer-deps-external";
9
- import packageJson from "./package.json";
10
-
11
- const projectRootDir = path.resolve(__dirname);
12
-
13
- export default [
14
- {
15
- input: "src/index.ts",
16
- output: [
17
- {
18
- file: packageJson.main,
19
- format: "cjs",
20
- sourcemap: true,
21
- },
22
- {
23
- file: packageJson.module,
24
- format: "esm",
25
- sourcemap: true,
26
- },
27
- ],
28
- plugins: [
29
- peerDepsExternal(),
30
- resolve(),
31
- commonjs(),
32
- typescript({
33
- tsconfig: "./tsconfig.rollup.json",
34
- }),
35
- terser(),
36
- alias({
37
- entries: [
38
- {
39
- find: "~",
40
- replacement: path.resolve(projectRootDir, "src"),
41
- },
42
- ],
43
- }),
44
- ],
45
- external: ["react", "react-dom"],
46
- },
47
- {
48
- input: "dist/esm/types/index.d.ts",
49
- output: [{ file: "dist/index.d.ts", format: "esm" }],
50
- plugins: [dts()],
51
- },
52
- ];
@@ -1,54 +0,0 @@
1
- import React from "react";
2
- import { ComponentMeta } from "@storybook/react";
3
- import { createTemplate } from "../../storybook";
4
- import { AppBar } from "./app-bar";
5
- import { DrawerProvider } from "../drawer";
6
-
7
- export default {
8
- title: "AppBars/AppBar",
9
- component: AppBar,
10
- parameters: {
11
- layout: "fullscreen",
12
- },
13
- } as ComponentMeta<typeof AppBar>;
14
-
15
- const Template = createTemplate((args) => {
16
- return (
17
- <DrawerProvider>
18
- <AppBar {...args} />
19
- </DrawerProvider>
20
- );
21
- });
22
-
23
- export const Default = Template.bind({});
24
- Default.args = {
25
- title: "Lorem ipsum",
26
- menu: true,
27
- };
28
-
29
- export const WithSearch = Template.bind({});
30
- WithSearch.args = {
31
- title: "Lorem ipsum",
32
- search: true,
33
- menu: true,
34
- };
35
-
36
- export const WithoutTitle = Template.bind({});
37
- WithoutTitle.args = {
38
- menu: true,
39
- };
40
-
41
- export const WihtoutMenu = Template.bind({});
42
- WihtoutMenu.args = {
43
- title: "Lorem ipsum",
44
- menu: false,
45
- };
46
-
47
- export const WithProfile = Template.bind({});
48
- WithProfile.args = {
49
- title: "Lorem ipsum",
50
- menu: true,
51
- profile: {
52
- name: "Test user",
53
- },
54
- };
@@ -1,142 +0,0 @@
1
- import React from "react";
2
- import { fireEvent, render, screen } from "../../tests";
3
- import { AppBar } from "./app-bar";
4
- import { DrawerProvider } from "../drawer";
5
- import { AppBarProfile } from "./app-bar.types";
6
- import userEvent from "@testing-library/user-event";
7
-
8
- const profile: AppBarProfile = {
9
- name: "John Smith",
10
- };
11
-
12
- describe("AppBar", () => {
13
- const renderComponent = ({
14
- search,
15
- title,
16
- menu,
17
- initialOpen,
18
- profile,
19
- }: {
20
- title?: string;
21
- search?: boolean;
22
- menu?: boolean;
23
- initialOpen?: boolean;
24
- profile?: AppBarProfile;
25
- } = {}) => {
26
- const onClickSignOut = jest.fn();
27
- const instance = render(
28
- <DrawerProvider initialOpen={initialOpen}>
29
- <AppBar
30
- title={title}
31
- menu={menu}
32
- search={search}
33
- profile={profile}
34
- onClickSignOut={onClickSignOut}
35
- />
36
- </DrawerProvider>,
37
- );
38
- return { ...instance, onClickSignOut };
39
- };
40
-
41
- const clickOutsideProfileMenu = () => {
42
- const child = screen.getByRole("presentation").firstChild;
43
- expect(child).toBeDefined();
44
- child && fireEvent.click(child);
45
- };
46
-
47
- describe("title", () => {
48
- it("wouldn't render a title if it's not defined", () => {
49
- renderComponent({ title: undefined });
50
-
51
- expect(screen.queryByRole("heading", { level: 1 })).not.toBeInTheDocument();
52
- });
53
-
54
- it("would render a title if it's defined", () => {
55
- renderComponent({ title: "Lorem ipsum" });
56
-
57
- expect(screen.queryByRole("heading", { level: 1, name: /lorem ipsum/i })).toBeInTheDocument();
58
- });
59
- });
60
-
61
- describe("menu", () => {
62
- it("wouldn't render a menu button if menu is not defined", () => {
63
- renderComponent();
64
-
65
- expect(screen.queryByRole("button", { name: /open drawer/i })).not.toBeInTheDocument();
66
- });
67
-
68
- it("wouldn't render a menu button if menu is false", () => {
69
- renderComponent({ menu: false });
70
-
71
- expect(screen.queryByRole("button", { name: /open drawer/i })).not.toBeInTheDocument();
72
- });
73
-
74
- it("would render a menu button if menu is true", () => {
75
- renderComponent({ menu: true });
76
-
77
- expect(screen.getByRole("button", { name: /open drawer/i })).toBeInTheDocument();
78
- });
79
- });
80
-
81
- describe("search", () => {
82
- it("wouldn't render a search box by default", () => {
83
- renderComponent();
84
-
85
- expect(screen.queryByRole("search")).not.toBeInTheDocument();
86
- });
87
-
88
- it("wouldn't render a search box if search is false", () => {
89
- renderComponent({ search: false });
90
-
91
- expect(screen.queryByRole("search")).not.toBeInTheDocument();
92
- });
93
-
94
- it("would render a search box if search is true", () => {
95
- renderComponent({ search: true });
96
-
97
- expect(screen.getByRole("search")).toBeInTheDocument();
98
- });
99
- });
100
-
101
- describe("profile", () => {
102
- it("wouldn't render the user profile if it's not set", () => {
103
- renderComponent({ profile: undefined });
104
-
105
- expect(screen.queryByRole("button", { name: /menu button/i })).not.toBeInTheDocument();
106
- });
107
-
108
- it("would render the user profile if the profile is defined", () => {
109
- renderComponent({ profile });
110
-
111
- expect(screen.getByRole("button", { name: /menu button/i })).toBeInTheDocument();
112
- });
113
-
114
- describe("the user click the profile button", () => {
115
- it("would open the menu", async () => {
116
- renderComponent({ profile });
117
-
118
- await userEvent.click(screen.getByRole("button", { name: /menu button/i }));
119
-
120
- expect(screen.getByRole("menu")).toBeInTheDocument();
121
- });
122
- });
123
-
124
- it("would call onClickSignOut if the user press the sign out button", async () => {
125
- const { onClickSignOut } = renderComponent({ profile });
126
-
127
- await userEvent.click(screen.getByRole("button", { name: /menu button/i }));
128
- await userEvent.click(screen.getByRole("menuitem", { name: /sign out/i }));
129
-
130
- expect(onClickSignOut).toHaveBeenCalledTimes(1);
131
- });
132
-
133
- it("would hide the menu if the focus changes to an external element", async () => {
134
- renderComponent({ profile, title: "lorem ipsum" });
135
-
136
- await userEvent.click(screen.getByRole("button", { name: /menu button/i }));
137
- clickOutsideProfileMenu();
138
-
139
- expect(screen.queryByRole("menu")).not.toBeInTheDocument();
140
- });
141
- });
142
- });
@@ -1,150 +0,0 @@
1
- import * as React from "react";
2
- import { styled, alpha } from "@mui/material/styles";
3
- import MuiAppBar from "@mui/material/AppBar";
4
- import Box from "@mui/material/Box";
5
- import Toolbar from "@mui/material/Toolbar";
6
- import IconButton from "@mui/material/IconButton";
7
- import Typography from "@mui/material/Typography";
8
- import InputBase from "@mui/material/InputBase";
9
- import MenuItem from "@mui/material/MenuItem";
10
- import Menu from "@mui/material/Menu";
11
- import MenuIcon from "@mui/icons-material/Menu";
12
- import SearchIcon from "@mui/icons-material/Search";
13
- import AccountCircle from "@mui/icons-material/AccountCircle";
14
- import { AppBarComponent, AppBarProps } from "./app-bar.types";
15
- import { useDrawer } from "../drawer/drawer.context";
16
-
17
- const Search = styled("div")(({ theme }) => ({
18
- position: "relative",
19
- borderRadius: theme.shape.borderRadius,
20
- backgroundColor: alpha(theme.palette.common.white, 0.15),
21
- "&:hover": {
22
- backgroundColor: alpha(theme.palette.common.white, 0.25),
23
- },
24
- marginRight: theme.spacing(2),
25
- marginLeft: 0,
26
- width: "100%",
27
- [theme.breakpoints.up("sm")]: {
28
- marginLeft: theme.spacing(3),
29
- width: "auto",
30
- },
31
- }));
32
-
33
- const SearchIconWrapper = styled("div")(({ theme }) => ({
34
- padding: theme.spacing(0, 2),
35
- height: "100%",
36
- position: "absolute",
37
- pointerEvents: "none",
38
- display: "flex",
39
- alignItems: "center",
40
- justifyContent: "center",
41
- }));
42
-
43
- const StyledInputBase = styled(InputBase)(({ theme }) => ({
44
- color: "inherit",
45
- "& .MuiInputBase-input": {
46
- padding: theme.spacing(1, 1, 1, 0),
47
- // vertical padding + font size from searchIcon
48
- paddingLeft: `calc(1em + ${theme.spacing(4)})`,
49
- transition: theme.transitions.create("width"),
50
- width: "100%",
51
- [theme.breakpoints.up("md")]: {
52
- width: "20ch",
53
- },
54
- },
55
- }));
56
-
57
- export const AppBar: AppBarComponent = ({
58
- search = false,
59
- title,
60
- menu = false,
61
- profile,
62
- onClickSignOut,
63
- ...rest
64
- }: AppBarProps) => {
65
- const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
66
- const { isOpen, open } = useDrawer();
67
-
68
- const handleMenu = (event: React.MouseEvent<HTMLElement>) => {
69
- setAnchorEl(event.currentTarget);
70
- };
71
-
72
- const handleClose = () => {
73
- setAnchorEl(null);
74
- };
75
-
76
- return (
77
- <MuiAppBar {...rest}>
78
- <Toolbar>
79
- {menu && (
80
- <IconButton
81
- color="inherit"
82
- aria-label="open drawer"
83
- onClick={open}
84
- edge="start"
85
- sx={{
86
- marginRight: 5,
87
- ...(isOpen && { display: "none" }),
88
- }}
89
- >
90
- <MenuIcon />
91
- </IconButton>
92
- )}
93
- {title && (
94
- <Typography
95
- variant="h6"
96
- component="h1"
97
- role="heading"
98
- aria-level={1}
99
- noWrap
100
- sx={{ display: { xs: "none", sm: "block" } }}
101
- >
102
- {title}
103
- </Typography>
104
- )}
105
- {search && (
106
- <Search role="search">
107
- <SearchIconWrapper>
108
- <SearchIcon />
109
- </SearchIconWrapper>
110
- <StyledInputBase placeholder="Search…" inputProps={{ "aria-label": "search" }} />
111
- </Search>
112
- )}
113
- <Box sx={{ flexGrow: 1 }} />
114
- {profile && (
115
- <Box sx={{ display: { xs: "none", md: "flex" } }}>
116
- <IconButton
117
- size="large"
118
- aria-controls="menu-appbar"
119
- aria-haspopup="true"
120
- aria-label="menu button"
121
- role="button"
122
- aria-expanded={Boolean(anchorEl)}
123
- onClick={handleMenu}
124
- color="inherit"
125
- >
126
- <AccountCircle />
127
- </IconButton>
128
- <Menu
129
- id="menu-appbar"
130
- anchorEl={anchorEl}
131
- anchorOrigin={{
132
- vertical: "top",
133
- horizontal: "right",
134
- }}
135
- keepMounted
136
- transformOrigin={{
137
- vertical: "top",
138
- horizontal: "right",
139
- }}
140
- open={Boolean(anchorEl)}
141
- onClose={handleClose}
142
- >
143
- <MenuItem onClick={onClickSignOut}>Sign out</MenuItem>
144
- </Menu>
145
- </Box>
146
- )}
147
- </Toolbar>
148
- </MuiAppBar>
149
- );
150
- };
@@ -1,17 +0,0 @@
1
- import { FunctionComponent, ReactElement } from "react";
2
- import { AppBarProps as MuiAppBarProps } from "@mui/material";
3
-
4
- export interface AppBarProfile {
5
- name: string;
6
- }
7
-
8
- export interface AppBarProps extends MuiAppBarProps {
9
- menu?: boolean;
10
- title?: string;
11
- search?: boolean;
12
- profile?: AppBarProfile;
13
- onClickSignOut: () => void;
14
- }
15
-
16
- export type AppBarComponent = FunctionComponent<AppBarProps>;
17
- export type AppBarElement = ReactElement<AppBarProps, AppBarComponent>;
@@ -1,3 +0,0 @@
1
- export * from "./mini-app-bar";
2
- export * from "./mini-app-bar";
3
- export * from "./app-bar.types";
@@ -1 +0,0 @@
1
- export * from "./mini-app-bar";
@@ -1,31 +0,0 @@
1
- import { styled } from "@mui/material/styles";
2
- import { AppBar } from "../app-bar";
3
- import { AppBarProps } from "@mui/material";
4
- import { drawerWidth } from "../../drawer/drawer.mixins";
5
- import { AppBarComponent } from "../app-bar.types";
6
- import { useDrawer } from "../../drawer/drawer.context";
7
-
8
- export const MiniAppBar: AppBarComponent = styled(AppBar)<AppBarProps>(({ theme }) => {
9
- const { isOpen } = useDrawer();
10
-
11
- return {
12
- zIndex: theme.zIndex.drawer + 1,
13
- transition: theme.transitions.create(["width", "margin"], {
14
- easing: theme.transitions.easing.sharp,
15
- duration: theme.transitions.duration.leavingScreen,
16
- }),
17
- ...(isOpen && {
18
- marginLeft: drawerWidth,
19
- width: `calc(100% - ${drawerWidth}px)`,
20
- transition: theme.transitions.create(["width", "margin"], {
21
- easing: theme.transitions.easing.sharp,
22
- duration: theme.transitions.duration.enteringScreen,
23
- }),
24
- }),
25
- };
26
- });
27
-
28
- MiniAppBar.defaultProps = {
29
- position: "fixed",
30
- menu: true,
31
- };