Skip to content

Notification Component #154

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

Merged
merged 29 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
06e963a
feat: notification component
MrFlashAccount Jun 27, 2022
44fe89d
feat: notification component
MrFlashAccount Jul 8, 2022
966972a
feat: increase target in configs
MrFlashAccount Jul 10, 2022
06a9652
feat: fix build problems
MrFlashAccount Jul 11, 2022
c1f350a
feat: fix dialog inside a dialog problem
MrFlashAccount Jul 11, 2022
447591f
fix: improve Notification component
MrFlashAccount Jul 11, 2022
d096a81
fix: squash bugs and add ability to react on dismiss on notification
MrFlashAccount Jul 12, 2022
4721876
fix: build issues
MrFlashAccount Jul 12, 2022
b37311c
Create young-flowers-melt.md
MrFlashAccount Jul 12, 2022
a02faa6
fix: border in list
MrFlashAccount Jul 12, 2022
2fcf87b
Merge remote-tracking branch 'origin/CUK-65' into CUK-65
MrFlashAccount Jul 12, 2022
0c112f8
fix: keyboard navigation within notifications bar
MrFlashAccount Jul 12, 2022
4588825
fix: flatten children in footer
MrFlashAccount Jul 12, 2022
905d3c9
fix: accept changes automatically in main branch
MrFlashAccount Jul 12, 2022
231a061
fix: types
MrFlashAccount Jul 12, 2022
8296361
fix: env url
MrFlashAccount Jul 12, 2022
82b61dd
fix: icon in safari
MrFlashAccount Jul 12, 2022
7865b3e
feat: migrate ui-kit to new notifications api
MrFlashAccount Jul 13, 2022
73aef43
feat: issues in notifications
MrFlashAccount Jul 13, 2022
ea939e1
feat: observer hook, use app root for the notifications instead of do…
MrFlashAccount Jul 14, 2022
dfe4f87
fix: token opacity and max-lines in description
MrFlashAccount Jul 14, 2022
e4dc68b
fix: toasts and ability to show a notification declaratively
MrFlashAccount Jul 18, 2022
029092b
Create gentle-apricots-provide.md
MrFlashAccount Jul 18, 2022
07073a8
feat: add shortcuts for notify api and improve typings
MrFlashAccount Jul 18, 2022
9df5ed3
fix: types
MrFlashAccount Jul 18, 2022
51c1ec3
fix: misc issues
MrFlashAccount Jul 18, 2022
769625b
fix: close button position
MrFlashAccount Jul 18, 2022
7870db8
fix: misc improvements in types
MrFlashAccount Jul 25, 2022
6d7db9b
fix: type error in Stories
MrFlashAccount Jul 25, 2022
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
5 changes: 5 additions & 0 deletions .changeset/gentle-apricots-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cube-dev/ui-kit": patch
---

Toast Component
5 changes: 5 additions & 0 deletions .changeset/young-flowers-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cube-dev/ui-kit": minor
---

[CUK-65](https://cubedevinc.atlassian.net/browse/CUK-65) - Notification component
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ jobs:
url: ${{ steps.publish_chromatic.outputs.url }}
env:
CHROMATIC_RETRIES: 5
LOG_LEVEL: 'error'
steps:
- uses: actions/checkout@v2
with:
Expand Down Expand Up @@ -89,6 +88,7 @@ jobs:
with:
exitZeroOnChanges: true
exitOnceUploaded: true
autoAcceptChanges: true
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}

deploy-docs:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ jobs:
with:
exitZeroOnChanges: true
exitOnceUploaded: true
onlyChanged: true
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}

- name: Comment PR
Expand All @@ -177,7 +178,7 @@ jobs:
runs-on: ubuntu-latest
environment:
name: Docs staging
url: ${{ steps.publish_docs.outputs.NETLIFY_PREVIEW_URL }}
url: ${{ steps.publish_docs.outputs.preview-url }}
env:
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
Expand Down
24 changes: 23 additions & 1 deletion .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// @ts-check
const webpack = require('webpack');

/**
* @readonly
* @type {import('@swc/core').Config}
*/
const swcConfig = {
jsc: {
parser: { syntax: 'typescript', tsx: true },
transform: { react: { runtime: 'automatic' } },
},
};

/** @type {import('@storybook/core-common').StorybookConfig} */
const config = {
staticDirs: ['../public'],
Expand All @@ -10,6 +21,7 @@ const config = {
name: 'webpack5',
options: { fsCache: true, lazyCompilation: true },
},
disableTelemetry: true,
},
features: {
postcss: false,
Expand All @@ -25,9 +37,19 @@ const config = {
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/addon-interactions',
{
name: 'storybook-addon-turbo-build',
options: {
esbuildMinifyOptions: { target: 'es2021' },
managerTranspiler: () => ({ loader: 'swc-loader', options: swcConfig }),
previewTranspiler: () => ({ loader: 'swc-loader', options: swcConfig }),
},
},
],
webpackFinal: async (config) => {
webpackFinal: (config) => {
config.plugins.push(new webpack.DefinePlugin({ SC_DISABLE_SPEEDY: true }));
config.performance.hints = false;

return config;
},
};
Expand Down
8 changes: 5 additions & 3 deletions .storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<style>
@import url('https://rsms.me/inter/inter.css');
</style>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap" rel="stylesheet">

<link rel="icon" href="/favicon.ico" sizes="any" />
<link
rel="icon"
href="/favicon-%STORYBOOK_MODE%-%NODE_ENV%.svg"
type="image/svg+xml"
/>

4 changes: 2 additions & 2 deletions .storybook/preview.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DocsContainer } from '@storybook/addon-docs';
import { configure } from '@storybook/testing-library';
import isChromatic from 'chromatic/isChromatic';
import { config } from 'react-transition-group';
import { DocsContainer } from '@storybook/addon-docs';
import { Root } from '../src';
import { configure } from '@storybook/testing-library';

configure({ testIdAttribute: 'data-qa', asyncUtilTimeout: 10000 });

Expand Down
9 changes: 0 additions & 9 deletions babel.config.js

This file was deleted.

38 changes: 21 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"email-validator": "^2.0.4",
"prismjs": "^1.25.0",
"react-is": "^17.0.0",
"react-keyed-flatten-children": "1.3.0",
"react-transition-group": "^4.4.2",
"tiny-invariant": "^1.2.0",
"valid-url": "^1.0.9"
Expand All @@ -118,30 +119,31 @@
"@changesets/cli": "^2.22.0",
"@commitlint/cli": "16.1.0",
"@commitlint/config-conventional": "16.0.0",
"@happy-dom/jest-environment": "4.0.0",
"@size-limit/file": "7.0.5",
"@size-limit/webpack": "7.0.5",
"@size-limit/webpack-why": "7.0.5",
"@statoscope/cli": "5.20.1",
"@storybook/addon-actions": "6.5.3",
"@storybook/addon-essentials": "6.5.3",
"@storybook/addon-interactions": "6.5.3",
"@storybook/addon-links": "6.5.3",
"@storybook/builder-webpack5": "6.5.3",
"@storybook/jest": "^0.0.10",
"@storybook/manager-webpack5": "^6.5.3",
"@storybook/react": "^6.5.3",
"@storybook/test-runner": "^0.1.0",
"@storybook/testing-library": "^0.0.11",
"@storybook/addon-actions": "6.5.9",
"@storybook/addon-essentials": "6.5.9",
"@storybook/addon-interactions": "6.5.9",
"@storybook/addon-links": "6.5.9",
"@storybook/builder-webpack5": "6.5.9",
"@storybook/manager-webpack5": "6.5.9",
"@storybook/react": "6.5.9",
"@storybook/jest": "0.0.10",
"@storybook/test-runner": "0.3.0",
"@storybook/testing-library": "0.0.13",
"@swc/core": "1.2.148",
"@swc/jest": "0.2.20",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/react-hooks": "^8.0.0",
"@testing-library/user-event": "14.2.0",
"@types/react": "^17.0.38",
"@types/react-is": "17.0.3",
"@types/react-dom": "^17.0.11",
"@types/react-test-renderer": "17.0.1",
"@types/react-transition-group": "^4.4.2",
"@typescript-eslint/eslint-plugin": "^5.8.1",
"@typescript-eslint/parser": "^5.8.1",
"bytes": "^3.1.0",
Expand All @@ -156,7 +158,6 @@
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-storybook": "^0.5.12",
"happy-dom": "4.0.0",
"husky": ">=6",
"jest": "27.5.1",
"jest-styled-components": "^7.0.8",
Expand All @@ -172,16 +173,19 @@
"rimraf": "^3.0.2",
"size-limit": "^7.0.5",
"styled-components": "5.3.0",
"typescript": "^4.5.4"
"typescript": "^4.5.4",
"storybook-addon-turbo-build": "1.1.0",
"swc-loader": "0.2.3"
},
"resolutions": {
"es5-ext": "0.10.53",
"prettier": "2.5.1"
"prettier": "2.5.1",
"@testing-library/user-event": "14.2.0"
},
"browserslist": [
"last 10 Chrome versions",
"last 5 Firefox versions",
"last 3 Safari versions"
"last 2 Chrome versions",
"last 2 Firefox versions",
"last 2 Safari major versions"
],
"license": "MIT"
}
4 changes: 4 additions & 0 deletions src/_internal/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export * from './use-deprecation-warning';
export * from './use-event';
export * from './use-sync-ref';
export * from './use-chained-callback';
export * from './use-timer';
13 changes: 13 additions & 0 deletions src/_internal/hooks/use-chained-callback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useEvent } from './use-event';

export function useChainedCallback(
...callbacks: (((...args: any) => any) | null | undefined | boolean)[]
) {
return useEvent((...args: any[]) => {
callbacks.forEach((callback) => {
if (typeof callback === 'function') {
callback(...args);
}
});
});
}
19 changes: 19 additions & 0 deletions src/_internal/hooks/use-event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useCallback } from 'react';
import { useSyncRef } from './use-sync-ref';

/**
* useEvent shim from the latest React RFC.
*
* @see https://github.com/reactjs/rfcs/pull/220
* @see https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md#internal-implementation
*/
export function useEvent<
Func extends (...args: Args) => Result,
Args extends Parameters<any> = Parameters<Func>,
Result extends ReturnType<any> = ReturnType<Func>,
>(callback: Func): (...args: Args) => Result {
const callbackRef = useSyncRef(callback);

return useCallback((...args) => callbackRef.current(...args), []);
}
11 changes: 11 additions & 0 deletions src/_internal/hooks/use-sync-ref.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { MutableRefObject, useLayoutEffect, useRef } from 'react';

export function useSyncRef<T>(value: T): MutableRefObject<T> {
const ref = useRef<T>(value);

useLayoutEffect(() => {
ref.current = value;
});

return ref;
}
2 changes: 2 additions & 0 deletions src/_internal/hooks/use-timer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './timer';
export * from './use-timer';
65 changes: 65 additions & 0 deletions src/_internal/hooks/use-timer/timer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
export class Timer {
private readonly callback: () => void;
private readonly delay: number;

private remaining: number;
private timerId: ReturnType<typeof setTimeout> | null = null;
private startTime: number | null = null;

private _status: 'stopped' | 'paused' | 'running' = 'stopped';

get status() {
return this._status;
}

private set status(status) {
this._status = status;
}

constructor(callback: () => unknown, delay: number) {
this.callback = callback;
this.delay = delay;
this.remaining = delay;

this.resume();
}

reset() {
this.clear();
this.remaining = this.delay;
this.status = 'stopped';
}

pause() {
if (this.timerId === null || this.startTime === null) {
return;
}

this.clear();
this.remaining -= Date.now() - this.startTime;
this.status = 'paused';
}

resume() {
if (this.timerId !== null) return;

this.startTime = Date.now();
this.clear();

this.timerId = setTimeout(() => {
this.reset();
this.callback();
}, this.remaining);

this.status = 'running';
}

private clear() {
if (this.timerId === null) {
return;
}

clearTimeout(this.timerId);
this.timerId = null;
}
}
Loading