├── .babelrc.es.json ├── .babelrc.json ├── .gitignore ├── .prettierrc.js ├── .storybook ├── main.js ├── preview-head.html └── preview.js ├── .vscode ├── extensions.json ├── launch.json └── settings.json ├── .yarn ├── plugins │ └── @yarnpkg │ │ ├── plugin-interactive-tools.cjs │ │ └── plugin-typescript.cjs └── releases │ └── yarn-3.2.0.cjs ├── .yarnrc.yml ├── LICENSE ├── package.json ├── src ├── components │ ├── common │ │ ├── Masks.tsx │ │ ├── SpaceBetween.tsx │ │ ├── animations.ts │ │ ├── dnd.tsx │ │ └── index.tsx │ ├── design │ │ ├── atoms │ │ │ ├── display │ │ │ │ ├── Avatar.stories.tsx │ │ │ │ ├── Avatar.tsx │ │ │ │ ├── Banner.stories.tsx │ │ │ │ ├── Banner.tsx │ │ │ │ ├── Category.stories.tsx │ │ │ │ ├── Category.tsx │ │ │ │ ├── Details.stories.tsx │ │ │ │ ├── Details.tsx │ │ │ │ ├── Error.stories.tsx │ │ │ │ ├── Error.tsx │ │ │ │ ├── Header.stories.tsx │ │ │ │ ├── Header.tsx │ │ │ │ ├── HiddenValue.stories.tsx │ │ │ │ ├── HiddenValue.tsx │ │ │ │ ├── Initials.stories.tsx │ │ │ │ ├── Initials.tsx │ │ │ │ ├── LineDivider.stories.tsx │ │ │ │ ├── LineDivider.tsx │ │ │ │ ├── Modal.stories.tsx │ │ │ │ ├── Modal.tsx │ │ │ │ ├── Tip.stories.tsx │ │ │ │ ├── Tip.tsx │ │ │ │ └── index.tsx │ │ │ ├── heading │ │ │ │ ├── H1.stories.tsx │ │ │ │ ├── H1.tsx │ │ │ │ ├── H2.stories.tsx │ │ │ │ ├── H2.tsx │ │ │ │ ├── H3.stories.tsx │ │ │ │ ├── H3.tsx │ │ │ │ ├── H4.stories.tsx │ │ │ │ ├── H4.tsx │ │ │ │ ├── H5.stories.tsx │ │ │ │ ├── H5.tsx │ │ │ │ ├── H6.stories.tsx │ │ │ │ ├── H6.tsx │ │ │ │ └── index.ts │ │ │ ├── index.ts │ │ │ ├── indicators │ │ │ │ ├── MessageDivider.stories.tsx │ │ │ │ ├── MessageDivider.tsx │ │ │ │ ├── Preloader.stories.tsx │ │ │ │ ├── Preloader.tsx │ │ │ │ ├── SaveStatus.stories.tsx │ │ │ │ ├── SaveStatus.tsx │ │ │ │ ├── Tooltip.stories.tsx │ │ │ │ ├── Tooltip.tsx │ │ │ │ ├── Turbo.stories.tsx │ │ │ │ ├── Turbo.tsx │ │ │ │ ├── Unreads.stories.tsx │ │ │ │ ├── Unreads.tsx │ │ │ │ ├── UserStatus.stories.tsx │ │ │ │ ├── UserStatus.tsx │ │ │ │ ├── UserTooltip.stories.tsx │ │ │ │ ├── UserTooltip.tsx │ │ │ │ └── index.tsx │ │ │ ├── inputs │ │ │ │ ├── Button.stories.tsx │ │ │ │ ├── Button.tsx │ │ │ │ ├── ButtonItem.stories.tsx │ │ │ │ ├── ButtonItem.tsx │ │ │ │ ├── CategoryButton.stories.tsx │ │ │ │ ├── CategoryButton.tsx │ │ │ │ ├── Checkbox.stories.tsx │ │ │ │ ├── Checkbox.tsx │ │ │ │ ├── ColourSwatches.stories.tsx │ │ │ │ ├── ColourSwatches.tsx │ │ │ │ ├── ComboBox.stories.tsx │ │ │ │ ├── ComboBox.tsx │ │ │ │ ├── IconButton.stories.tsx │ │ │ │ ├── IconButton.tsx │ │ │ │ ├── InputBox.stories.tsx │ │ │ │ ├── InputBox.tsx │ │ │ │ ├── OverrideSwitch.stories.tsx │ │ │ │ ├── OverrideSwitch.tsx │ │ │ │ ├── Radio.stories.tsx │ │ │ │ ├── Radio.tsx │ │ │ │ ├── TextArea.stories.tsx │ │ │ │ ├── TextArea.tsx │ │ │ │ └── index.tsx │ │ │ └── layout │ │ │ │ ├── Centred.tsx │ │ │ │ ├── Column.tsx │ │ │ │ ├── Row.tsx │ │ │ │ └── index.ts │ │ ├── index.tsx │ │ ├── media │ │ │ ├── editor │ │ │ │ ├── Editor.stories.tsx.disabled │ │ │ │ └── Editor.tsx.disabled │ │ │ ├── index.ts │ │ │ └── picker │ │ │ │ ├── EmojiPreview.tsx │ │ │ │ ├── Picker.stories.tsx │ │ │ │ └── Picker.tsx │ │ ├── messaging │ │ │ ├── Info.tsx │ │ │ ├── Message.stories.tsx │ │ │ ├── Message.tsx │ │ │ └── index.ts │ │ └── navigation │ │ │ ├── index.ts │ │ │ └── servers │ │ │ └── list │ │ │ ├── Item.tsx │ │ │ ├── ListFooter.tsx │ │ │ ├── ListHeader.tsx │ │ │ ├── ServerList.stories.tsx │ │ │ ├── ServerList.tsx │ │ │ └── Swoosh.tsx │ ├── pages │ │ ├── index.tsx │ │ └── settings │ │ │ ├── account │ │ │ ├── AccountDetail.stories.tsx │ │ │ ├── AccountDetail.tsx │ │ │ └── index.tsx │ │ │ └── permissions │ │ │ ├── PermissionsLayout.stories.tsx │ │ │ ├── PermissionsLayout.tsx │ │ │ ├── RoleList.stories.tsx │ │ │ ├── RoleList.tsx │ │ │ └── index.tsx │ └── tools │ │ ├── Stacked.tsx │ │ ├── form │ │ ├── Form.tsx │ │ ├── InputElement.tsx │ │ ├── ModalForm.tsx │ │ └── index.tsx │ │ └── index.tsx ├── index.ts ├── lib │ ├── closeHook.ts │ ├── context.ts │ ├── debounce.ts │ ├── index.ts │ ├── internal.tsx │ ├── internal │ │ └── emojis.ts │ └── isTouchscreenDevice.ts ├── styles │ ├── common.css │ ├── dark.css │ └── light.css └── types.d.ts ├── tsconfig.json └── yarn.lock /.babelrc.es.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-react", 4 | "@babel/preset-typescript", 5 | [ 6 | "@babel/preset-env", 7 | { 8 | "modules": false, 9 | "exclude": ["@babel/plugin-transform-regenerator"] 10 | } 11 | ], 12 | "minify" 13 | ], 14 | "plugins": [ 15 | [ 16 | "babel-plugin-styled-components", 17 | { 18 | "displayName": true, 19 | "fileName": false 20 | } 21 | ], 22 | "@babel/plugin-proposal-nullish-coalescing-operator" 23 | ], 24 | "comments": false 25 | } 26 | -------------------------------------------------------------------------------- /.babelrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-react", 4 | "@babel/preset-typescript", 5 | [ 6 | "@babel/preset-env", 7 | { 8 | "targets": { 9 | "edge": "17", 10 | "firefox": "60", 11 | "chrome": "67", 12 | "safari": "11.1" 13 | }, 14 | "exclude": ["@babel/plugin-transform-regenerator"] 15 | } 16 | ], 17 | "minify" 18 | ], 19 | "plugins": [ 20 | [ 21 | "babel-plugin-styled-components", 22 | { 23 | "displayName": true, 24 | "fileName": false 25 | } 26 | ], 27 | "@babel/plugin-proposal-nullish-coalescing-operator" 28 | ], 29 | "comments": false 30 | } 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ._stories.default 2 | node_modules 3 | storybook-static 4 | .vercel 5 | /lib 6 | /esm 7 | 8 | .yarn/cache 9 | .yarn/install-state.gz 10 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | tabWidth: 4, 3 | trailingComma: "all", 4 | jsxBracketSameLine: true, 5 | importOrder: [ 6 | "preact|classnames|.scss$", 7 | "/(lib)", 8 | "/(redux|mobx)", 9 | "/(context)", 10 | "/(ui|common)|.svg|.webp|.png|.jpg$", 11 | "^[./]", 12 | ], 13 | importOrderSeparation: true, 14 | }; 15 | -------------------------------------------------------------------------------- /.storybook/main.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | stories: [ 3 | "../src/**/*.stories.mdx", 4 | "../src/**/*.stories.@(js|jsx|ts|tsx)", 5 | ], 6 | addons: [ 7 | "@storybook/addon-links", 8 | "@storybook/addon-essentials", 9 | "storybook-dark-mode", 10 | "storybook-rtl-addon", 11 | ], 12 | framework: "@storybook/react", 13 | }; 14 | -------------------------------------------------------------------------------- /.storybook/preview-head.html: -------------------------------------------------------------------------------- 1 | 8 | -------------------------------------------------------------------------------- /.storybook/preview.js: -------------------------------------------------------------------------------- 1 | import { themes } from "@storybook/theming"; 2 | 3 | import "../src/styles/dark.css"; 4 | import "../src/styles/light.css"; 5 | import "../src/styles/common.css"; 6 | 7 | export const parameters = { 8 | actions: { argTypesRegex: "^on[A-Z].*" }, 9 | controls: { 10 | matchers: { 11 | color: /(background|color)$/i, 12 | date: /Date$/, 13 | }, 14 | }, 15 | darkMode: { 16 | classTarget: "html", 17 | stylePreview: true, 18 | // Override the default dark theme 19 | dark: { ...themes.dark }, 20 | // Override the default light theme 21 | light: { ...themes.normal }, 22 | }, 23 | }; 24 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"] 3 | } 4 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "pwa-chrome", 9 | "request": "launch", 10 | "name": "Launch Chrome against localhost", 11 | "url": "http://localhost:6006", 12 | "webRoot": "${workspaceFolder}" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.defaultFormatter": "esbenp.prettier-vscode", 3 | "editor.formatOnSave": true 4 | } 5 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | 3 | plugins: 4 | - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs 5 | spec: "@yarnpkg/plugin-interactive-tools" 6 | - path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs 7 | spec: "@yarnpkg/plugin-typescript" 8 | 9 | yarnPath: .yarn/releases/yarn-3.2.0.cjs 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@revoltchat/ui", 3 | "version": "1.0.77", 4 | "description": "Revolt UI component library", 5 | "type": "commonjs", 6 | "main": "lib/index.js", 7 | "module": "esm/index.js", 8 | "types": "esm/index.d.ts", 9 | "repository": "https://github.com/revoltchat/components", 10 | "author": "Paul Makles ", 11 | "license": "AGPL-3.0-or-later", 12 | "dependencies": { 13 | "@styled-icons/boxicons-logos": "^10.38.0", 14 | "@styled-icons/boxicons-regular": "^10.38.0", 15 | "@styled-icons/boxicons-solid": "^10.38.0", 16 | "@tippyjs/react": "^4.2.6", 17 | "mobx": "^6.6.0", 18 | "mobx-react-lite": "^3.4.0", 19 | "prismjs": "^1.28.0", 20 | "react-beautiful-dnd": "^13.1.0", 21 | "react-device-detect": "^2.2.2", 22 | "react-virtuoso": "^2.12.0" 23 | }, 24 | "devDependencies": { 25 | "@babel/cli": "^7.17.6", 26 | "@babel/core": "^7.17.9", 27 | "@babel/plugin-proposal-nullish-coalescing-operator": "^7.17.12", 28 | "@babel/preset-env": "^7.18.2", 29 | "@babel/preset-react": "^7.17.12", 30 | "@babel/preset-typescript": "^7.17.12", 31 | "@storybook/addon-actions": "^6.5.5", 32 | "@storybook/addon-essentials": "^6.5.5", 33 | "@storybook/addon-knobs": "^6.4.0", 34 | "@storybook/addon-links": "^6.5.5", 35 | "@storybook/client-api": "^6.5.12", 36 | "@storybook/react": "^6.5.5", 37 | "@types/lodash.isequal": "^4.5.5", 38 | "@types/prismjs": "^1", 39 | "@types/react": "^18", 40 | "@types/react-beautiful-dnd": "=13.0.0", 41 | "@types/react-dom": "^18", 42 | "@types/styled-components": "^5.1.25", 43 | "babel-loader": "^8.2.4", 44 | "babel-plugin-styled-components": "^2.0.7", 45 | "babel-preset-minify": "^0.5.1", 46 | "react": "^17.0.2", 47 | "react-dom": "^17.0.2", 48 | "revolt.js": "^6", 49 | "rimraf": "^3.0.2", 50 | "storybook-dark-mode": "^1.1.0", 51 | "storybook-rtl-addon": "^0.3.3", 52 | "styled-components": "^5.3.5", 53 | "tsc-watch": "^5.0.3", 54 | "typescript": "^4.8.3" 55 | }, 56 | "scripts": { 57 | "build": "npm run build:clean && npm run build:esm && npm run build:bundle", 58 | "build:clean": "rimraf dist esm", 59 | "build:esm": "babel src --no-babelrc --out-dir esm --extensions \".ts,.tsx\" --config-file ./.babelrc.es && tsc", 60 | "watch:esm": "tsc-watch", 61 | "build:bundle": "babel src --out-dir lib --extensions \".ts,.tsx\"", 62 | "watch:bundle": "npm run build:bundle --watch", 63 | "storybook": "start-storybook -p 6006", 64 | "build-storybook": "build-storybook" 65 | }, 66 | "files": [ 67 | "LICENSE", 68 | "package.json", 69 | "lib", 70 | "src", 71 | "esm" 72 | ], 73 | "packageManager": "yarn@3.2.0", 74 | "peerDependencies": { 75 | "revolt.js": "*" 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/components/common/Masks.tsx: -------------------------------------------------------------------------------- 1 | // This file must be imported and used at least once for SVG masks. 2 | import React from "react"; 3 | 4 | export function Masks() { 5 | return ( 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | {/** 23 | * Legacy masks from old code 24 | */} 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | {/*CUSTOM AVATAR FRAMES*/} 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 56 | 57 | 58 | 59 | ); 60 | } 61 | -------------------------------------------------------------------------------- /src/components/common/SpaceBetween.tsx: -------------------------------------------------------------------------------- 1 | import styled from "styled-components"; 2 | 3 | export const SpaceBetween = styled.div` 4 | display: flex; 5 | align-items: center; 6 | justify-content: space-between; 7 | `; 8 | -------------------------------------------------------------------------------- /src/components/common/animations.ts: -------------------------------------------------------------------------------- 1 | import { keyframes } from "styled-components"; 2 | 3 | export const animationFadeIn = keyframes` 4 | 0% {opacity: 0;} 5 | 70% {opacity: 0;} 6 | 100% {opacity: 1;} 7 | `; 8 | 9 | export const animationFadeOut = keyframes` 10 | 0% {opacity: 1;} 11 | 70% {opacity: 0;} 12 | 100% {opacity: 0;} 13 | `; 14 | 15 | export const animationZoomIn = keyframes` 16 | 0% {transform: scale(0.5);} 17 | 98% {transform: scale(1.01);} 18 | 100% {transform: scale(1);} 19 | `; 20 | 21 | export const animationZoomOut = keyframes` 22 | 0% {transform: scale(1);} 23 | 100% {transform: scale(0.5);} 24 | `; 25 | -------------------------------------------------------------------------------- /src/components/common/dnd.tsx: -------------------------------------------------------------------------------- 1 | import React, { useCallback, useEffect, useState } from "react"; 2 | import { DraggableProvided, DropResult } from "react-beautiful-dnd"; 3 | import styled from "styled-components"; 4 | 5 | export type DraggableProps = { 6 | provided: DraggableProvided; 7 | item: T; 8 | isDragging: boolean; 9 | }; 10 | 11 | /** 12 | * Base component for height preserving container 13 | */ 14 | const HeightPreservingContainer = styled.div` 15 | &:empty { 16 | min-height: calc(var(--child-height)); 17 | box-sizing: border-box; 18 | } 19 | `; 20 | 21 | /** 22 | * Height Preserving Item 23 | * 24 | * https://codesandbox.io/s/react-virutoso-with-react-beautiful-dnd-e6vmq?file=/src/index.js:1734-2319 25 | */ 26 | export function useHeightPreservingItem() { 27 | return useCallback( 28 | ({ 29 | children, 30 | ...props 31 | }: { 32 | children: React.ReactNode; 33 | "data-known-size": number; 34 | }) => { 35 | const [size, setSize] = useState(0); 36 | const knownSize = props["data-known-size"]; 37 | 38 | useEffect(() => { 39 | setSize((prevSize) => { 40 | return knownSize == 0 ? prevSize : knownSize; 41 | }); 42 | }, [knownSize]); 43 | 44 | return ( 45 | 52 | {children} 53 | 54 | ); 55 | }, 56 | [], 57 | ); 58 | } 59 | 60 | /** 61 | * Short-hand for creating object with Item component 62 | * @returns Components 63 | */ 64 | export function useDndComponents() { 65 | return { 66 | Item: useHeightPreservingItem(), 67 | }; 68 | } 69 | 70 | /** 71 | * Re-order a list 72 | * 73 | * https://codesandbox.io/s/react-virutoso-with-react-beautiful-dnd-e6vmq?file=/src/index.js:732-923 74 | * 75 | * @param list Input list 76 | * @param startIndex Start index 77 | * @param endIndex End index 78 | * @returns New list 79 | */ 80 | export function reorder(list: any[], startIndex: number, endIndex: number) { 81 | const result = Array.from(list); 82 | const [removed] = result.splice(startIndex, 1); 83 | result.splice(endIndex, 0, removed); 84 | 85 | return result; 86 | } 87 | 88 | /** 89 | * Create a new drag end handler 90 | * 91 | * https://codesandbox.io/s/react-virutoso-with-react-beautiful-dnd-e6vmq?file=/src/index.js:1377-1733 92 | * 93 | * @param setItems Item setter 94 | * @returns Drag end handler 95 | */ 96 | export function useDragEndReorder( 97 | setItems: (v: (items: any[]) => any[]) => void, 98 | ) { 99 | return useCallback( 100 | (result: DropResult) => { 101 | if (!result.destination) { 102 | return; 103 | } 104 | if (result.source.index === result.destination.index) { 105 | return; 106 | } 107 | 108 | setItems((items) => 109 | reorder(items, result.source.index, result.destination!.index), 110 | ); 111 | }, 112 | [setItems], 113 | ); 114 | } 115 | 116 | /** 117 | * Modified version of above function to provide simple reordering interface 118 | * 119 | * @param reorder Reorder function 120 | * @returns Drag end handler 121 | */ 122 | export function useDragEndCustomReorder( 123 | reorder: (source: number, dest: number) => void, 124 | ) { 125 | return useCallback( 126 | (result: DropResult) => { 127 | if (!result.destination) { 128 | return; 129 | } 130 | if (result.source.index === result.destination.index) { 131 | return; 132 | } 133 | 134 | reorder(result.source.index, result.destination!.index); 135 | }, 136 | [reorder], 137 | ); 138 | } 139 | -------------------------------------------------------------------------------- /src/components/common/index.tsx: -------------------------------------------------------------------------------- 1 | export * from "./dnd"; 2 | export * from "./animations"; 3 | export { Masks } from "./Masks"; 4 | export { SpaceBetween } from "./SpaceBetween"; 5 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Avatar.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { ComponentStory, ComponentMeta } from "@storybook/react"; 3 | 4 | import { Avatar } from "./Avatar"; 5 | import { MaskDecorator } from "../../../../lib/internal"; 6 | 7 | export default { 8 | title: "Design System/Atoms/Display/Avatar", 9 | component: Avatar, 10 | argTypes: { 11 | size: { 12 | name: "Size", 13 | type: "number", 14 | defaultValue: 256, 15 | }, 16 | src: { 17 | name: "Source", 18 | type: "string", 19 | defaultValue: 20 | "https://autumn.revolt.chat/attachments/Jzd9uX7iFg4cElkbeNV4vsiaUkMkXNguO2X7rEMajl/ul5PFf4_dySDWGeOJ4WIOTlnL8uF-h4d4gn5TISB1g.png", 21 | }, 22 | fallback: { 23 | name: "Fallback Component", 24 | type: "string", 25 | }, 26 | holepunch: { 27 | name: "Holepunch", 28 | }, 29 | overlay: { 30 | name: "Overlay Components", 31 | type: "symbol", 32 | }, 33 | }, 34 | decorators: [MaskDecorator], 35 | } as ComponentMeta; 36 | 37 | const Template: ComponentStory = (args) => ; 38 | 39 | export const Default = Template.bind({}); 40 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Avatar.tsx: -------------------------------------------------------------------------------- 1 | import React, { ReactNode } from "react"; 2 | import styled, { css } from "styled-components"; 3 | import { Initials } from "./Initials"; 4 | 5 | const Image = styled.img` 6 | width: 100%; 7 | height: 100%; 8 | object-fit: cover; 9 | border-radius: 50%; 10 | `; 11 | 12 | const FallbackBase = styled.div` 13 | width: 100%; 14 | height: 100%; 15 | border-radius: 50%; 16 | 17 | display: flex; 18 | align-items: center; 19 | justify-content: center; 20 | 21 | font-weight: 600; 22 | font-size: 0.75rem; 23 | color: var(--foreground); 24 | background: var(--secondary-background); 25 | `; 26 | 27 | const ParentBase = styled.svg>` 28 | user-select: none; 29 | 30 | foreignObject { 31 | transition: 150ms ease filter; 32 | } 33 | 34 | ${(props) => 35 | props.interactive && 36 | css` 37 | cursor: pointer; 38 | 39 | &:hover foreignObject { 40 | filter: brightness(0.8); 41 | } 42 | `} 43 | `; 44 | 45 | export type Props = { 46 | /** 47 | * Avatar size 48 | */ 49 | size?: number; 50 | 51 | /** 52 | * Image source 53 | */ 54 | src?: string; 55 | 56 | /** 57 | * Fallback if no source 58 | */ 59 | fallback?: string | ReactNode; 60 | 61 | /** 62 | * Punch a hole through the avatar 63 | */ 64 | holepunch?: "bottom-right" | "top-right" | "right" | "none" | false; 65 | 66 | /** 67 | * Specify overlay component 68 | */ 69 | overlay?: ReactNode; 70 | 71 | /** 72 | * Whether this icon is interactive 73 | */ 74 | interactive?: boolean; 75 | }; 76 | 77 | /** 78 | * Generic Avatar component 79 | * 80 | * Partially inspired by Adw.Avatar API, we allow users to specify a fallback component (usually just text) to display in case the URL is invalid. 81 | */ 82 | export function Avatar({ 83 | size, 84 | holepunch, 85 | fallback, 86 | src, 87 | overlay, 88 | interactive, 89 | }: Props) { 90 | return ( 91 | 96 | 102 | {src && } 103 | {!src && ( 104 | 105 | {typeof fallback === "string" ? ( 106 | 107 | ) : ( 108 | fallback 109 | )} 110 | 111 | )} 112 | 113 | {overlay} 114 | 115 | ); 116 | } 117 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Banner.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { ComponentStory, ComponentMeta } from "@storybook/react"; 3 | 4 | import { Banner } from "./Banner"; 5 | 6 | export default { 7 | title: "Design System/Atoms/Display/Banner", 8 | component: Banner, 9 | argTypes: { 10 | children: { 11 | name: "Content", 12 | type: "string", 13 | defaultValue: "I am a banner!", 14 | }, 15 | }, 16 | } as ComponentMeta; 17 | 18 | const Template: ComponentStory = (args) => ; 19 | 20 | export const Default = Template.bind({}); 21 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Banner.tsx: -------------------------------------------------------------------------------- 1 | import styled from "styled-components"; 2 | 3 | export const Banner = styled.div` 4 | padding: 8px; 5 | font-size: 0.875rem; 6 | text-align: center; 7 | 8 | color: var(--accent); 9 | background: var(--primary-background); 10 | `; 11 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Category.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { ComponentStory, ComponentMeta } from "@storybook/react"; 3 | 4 | import { Category } from "./Category"; 5 | 6 | export default { 7 | title: "Design System/Atoms/Display/Category", 8 | component: Category, 9 | argTypes: { 10 | compact: { 11 | name: "Compact", 12 | type: "boolean", 13 | defaultValue: false, 14 | }, 15 | children: { 16 | name: "Content", 17 | type: "string", 18 | defaultValue: "Some Category", 19 | }, 20 | }, 21 | } as ComponentMeta; 22 | 23 | const Template: ComponentStory = (args) => ( 24 | 25 | ); 26 | 27 | export const Default = Template.bind({}); 28 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Category.tsx: -------------------------------------------------------------------------------- 1 | import styled from "styled-components"; 2 | 3 | export interface Props { 4 | compact?: boolean; 5 | } 6 | 7 | export const Category = styled.div` 8 | font-size: 0.75rem; 9 | font-weight: 700; 10 | color: var(--foreground); 11 | text-transform: uppercase; 12 | 13 | margin-top: 4px; 14 | margin-bottom: 4px; 15 | white-space: nowrap; 16 | padding: ${(props) => (props.compact ? "0 4px" : "6px 0 6px 8px")}; 17 | 18 | display: flex; 19 | align-items: center; 20 | flex-direction: row; 21 | justify-content: space-between; 22 | 23 | &:first-child { 24 | margin-top: 0; 25 | padding-top: 0; 26 | } 27 | `; 28 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Details.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { ComponentStory, ComponentMeta } from "@storybook/react"; 3 | import { ChevronDown, ChevronRight } from "@styled-icons/boxicons-regular"; 4 | 5 | import { Details } from "./Details"; 6 | 7 | export default { 8 | title: "Design System/Atoms/Display/Details", 9 | component: Details, 10 | argTypes: { 11 | children: { 12 | name: "Content", 13 | type: "string", 14 | defaultValue: "Textual Content", 15 | }, 16 | summary: { 17 | name: "Summary", 18 | type: "string", 19 | defaultValue: "Details Component", 20 | }, 21 | sticky: { 22 | name: "Sticky", 23 | type: "boolean", 24 | defaultValue: false, 25 | }, 26 | large: { 27 | name: "Large", 28 | type: "boolean", 29 | defaultValue: false, 30 | }, 31 | }, 32 | } as ComponentMeta; 33 | 34 | const Template: ComponentStory = (args) => { 35 | const { summary, children, ...rest } = args; 36 | 37 | return ( 38 |
39 |
40 | 41 | {summary} 42 | 43 | {children} 44 |
45 |
46 | ); 47 | }; 48 | 49 | export const Default = Template.bind({}); 50 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Details.tsx: -------------------------------------------------------------------------------- 1 | import styled, { css } from "styled-components"; 2 | 3 | export interface Props { 4 | sticky?: boolean; 5 | large?: boolean; 6 | } 7 | 8 | export const Details = styled.details` 9 | // ! FIXME: clean up CSS 10 | summary { 11 | ${(props) => 12 | props.sticky && 13 | css` 14 | top: -1px; 15 | z-index: 10; 16 | position: sticky; 17 | `} 18 | 19 | ${(props) => 20 | props.large && 21 | css` 22 | /*padding: 5px 0;*/ 23 | background: var(--primary-background); 24 | color: var(--secondary-foreground); 25 | 26 | .padding { 27 | /*TOFIX: make this applicable only for the friends list menu, DO NOT REMOVE.*/ 28 | display: flex; 29 | align-items: center; 30 | padding: 5px 0; 31 | margin: 0.8em 0px 0.4em; 32 | cursor: pointer; 33 | } 34 | `} 35 | 36 | outline: none; 37 | cursor: pointer; 38 | list-style: none; 39 | user-select: none; 40 | align-items: center; 41 | transition: 0.2s opacity; 42 | 43 | font-size: 0.75rem; 44 | font-weight: 600; 45 | text-transform: uppercase; 46 | 47 | &::marker, 48 | &::-webkit-details-marker { 49 | display: none; 50 | } 51 | 52 | .title { 53 | flex-grow: 1; 54 | margin-top: 1px; 55 | text-overflow: ellipsis; 56 | overflow: hidden; 57 | white-space: nowrap; 58 | } 59 | 60 | .padding { 61 | display: flex; 62 | align-items: center; 63 | 64 | > svg { 65 | flex-shrink: 0; 66 | margin-inline-end: 4px; 67 | transition: 0.2s ease transform; 68 | } 69 | } 70 | 71 | gap: 4px; 72 | display: flex; 73 | align-items: center; 74 | } 75 | 76 | &:not([open]) { 77 | summary { 78 | opacity: 0.7; 79 | } 80 | 81 | summary svg { 82 | transform: rotateZ(-90deg); 83 | } 84 | } 85 | `; 86 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Error.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { ComponentStory, ComponentMeta } from "@storybook/react"; 3 | 4 | import { Error } from "./Error"; 5 | 6 | export default { 7 | title: "Design System/Atoms/Display/Error", 8 | component: Error, 9 | argTypes: { 10 | children: { 11 | name: "Content", 12 | type: "string", 13 | defaultValue: "Child Element", 14 | }, 15 | error: { 16 | name: "Error", 17 | type: "string", 18 | defaultValue: "Something went wrong!", 19 | }, 20 | }, 21 | } as ComponentMeta; 22 | 23 | const Template: ComponentStory = (args) => ; 24 | 25 | export const Default = Template.bind({}); 26 | 27 | export const ContentPassthrough = Template.bind({}); 28 | 29 | ContentPassthrough.args = { 30 | error: "", 31 | }; 32 | 33 | export const OnlyError = Template.bind({}); 34 | 35 | OnlyError.args = { 36 | children: "", 37 | }; 38 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Error.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import styled from "styled-components"; 3 | 4 | const Base = styled.span` 5 | gap: 6px; 6 | display: flex; 7 | align-items: center; 8 | flex-direction: row; 9 | color: var(--foreground); 10 | 11 | .error { 12 | font-weight: 600; 13 | color: var(--error); 14 | } 15 | `; 16 | 17 | export interface Props { 18 | error?: React.ReactNode; 19 | children?: React.ReactNode; 20 | } 21 | 22 | export function Error({ error, children }: Props) { 23 | return ( 24 | 25 | {children} 26 | 27 | {children && error && <> · } 28 | {error} 29 | 30 | 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Header.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { ComponentStory, ComponentMeta } from "@storybook/react"; 3 | 4 | import { Header } from "./Header"; 5 | 6 | export default { 7 | title: "Design System/Atoms/Display/Header", 8 | component: Header, 9 | argTypes: { 10 | children: { 11 | name: "Content", 12 | type: "string", 13 | defaultValue: "Header Title", 14 | }, 15 | palette: { 16 | name: "Palette", 17 | control: "radio", 18 | options: ["primary", "secondary"], 19 | defaultValue: "primary", 20 | }, 21 | topBorder: { name: "Top Border", type: "boolean", defaultValue: false }, 22 | bottomBorder: { 23 | name: "Bottom Border", 24 | type: "boolean", 25 | defaultValue: false, 26 | }, 27 | withBackground: { 28 | name: "Has background?", 29 | type: "boolean", 30 | defaultValue: false, 31 | }, 32 | withTransparency: { 33 | name: "Has transparency?", 34 | type: "boolean", 35 | defaultValue: false, 36 | }, 37 | }, 38 | } as ComponentMeta; 39 | 40 | const Template: ComponentStory = (args) =>
; 41 | 42 | export const Default = Template.bind({}); 43 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Header.tsx: -------------------------------------------------------------------------------- 1 | import styled, { css } from "styled-components"; 2 | 3 | export interface Props { 4 | readonly palette: "primary" | "secondary"; 5 | 6 | readonly topBorder?: boolean; 7 | readonly bottomBorder?: boolean; 8 | 9 | readonly withBackground?: boolean; 10 | readonly withTransparency?: boolean; 11 | } 12 | 13 | export const Header = styled.div` 14 | gap: 10px; 15 | flex: 0 auto; 16 | display: flex; 17 | flex-shrink: 0; 18 | padding: 0 16px; 19 | align-items: center; 20 | 21 | font-weight: 600; 22 | user-select: none; 23 | 24 | height: var(--header-height); 25 | 26 | color: var(--foreground); 27 | background-size: cover !important; 28 | background-position: center !important; 29 | 30 | svg { 31 | flex-shrink: 0; 32 | } 33 | 34 | ${(props) => 35 | props.withTransparency 36 | ? css` 37 | background-color: rgba( 38 | var(--${props.palette}-header-rgb), 39 | max(var(--min-opacity), 0.75) 40 | ); 41 | backdrop-filter: blur(20px); 42 | 43 | width: 100%; 44 | z-index: 20; 45 | position: absolute; 46 | ` 47 | : css` 48 | background-color: var(--${props.palette}-header); 49 | `} 50 | 51 | ${(props) => 52 | props.withBackground && 53 | css` 54 | align-items: flex-end; 55 | height: 120px !important; 56 | 57 | text-shadow: 0px 0px 1px black; 58 | `} 59 | 60 | ${(props) => 61 | props.topBorder && 62 | css` 63 | border-start-start-radius: 8px; 64 | `} 65 | 66 | ${(props) => 67 | props.bottomBorder && 68 | css` 69 | border-end-start-radius: 8px; 70 | `} 71 | `; 72 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/HiddenValue.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { ComponentStory, ComponentMeta } from "@storybook/react"; 3 | 4 | import { HiddenValue } from "./HiddenValue"; 5 | import { ContextDecorator } from "../../../../lib/internal"; 6 | 7 | export default { 8 | title: "Design System/Atoms/Display/Hidden Value", 9 | component: HiddenValue, 10 | argTypes: { 11 | value: { 12 | name: "Value", 13 | defaultValue: "user@example.com", 14 | }, 15 | placeholder: { 16 | name: "Placeholder", 17 | defaultValue: "•••••••••••@••••••.•••", 18 | }, 19 | }, 20 | decorators: [ContextDecorator], 21 | } as ComponentMeta; 22 | 23 | const Template: ComponentStory = (args) => ( 24 | 25 | ); 26 | 27 | export const Default = Template.bind({}); 28 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/HiddenValue.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import styled from "styled-components"; 3 | import { useText } from "../../../../lib"; 4 | 5 | const Toggle = styled.a` 6 | font-size: 13px; 7 | `; 8 | 9 | interface Props { 10 | /** 11 | * Actual value to show 12 | */ 13 | value: string; 14 | 15 | /** 16 | * Placeholder value when hidden 17 | */ 18 | placeholder: string; 19 | } 20 | 21 | export function HiddenValue({ value, placeholder }: Props) { 22 | const [shown, set] = useState(false); 23 | const Text = useText(); 24 | 25 | return ( 26 | <> 27 | {shown ? value : placeholder}{" "} 28 | { 30 | ev.stopPropagation(); 31 | set(!shown); 32 | }}> 33 | 38 | 39 | 40 | ); 41 | } 42 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Initials.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { ComponentStory, ComponentMeta } from "@storybook/react"; 3 | 4 | import { Initials } from "./Initials"; 5 | import { Masks } from "../../../common"; 6 | import { MaskDecorator } from "../../../../lib/internal"; 7 | 8 | export default { 9 | title: "Design System/Atoms/Display/Initials", 10 | component: Initials, 11 | argTypes: { 12 | input: { 13 | name: "Input String", 14 | defaultValue: "John Smith", 15 | }, 16 | maxLength: { 17 | name: "Max Length", 18 | }, 19 | }, 20 | decorators: [MaskDecorator], 21 | } as ComponentMeta; 22 | 23 | const Template: ComponentStory = (args) => ( 24 | 25 | ); 26 | 27 | export const Default = Template.bind({}); 28 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Initials.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | export type Props = { 4 | /** 5 | * Input string 6 | */ 7 | input: string; 8 | 9 | /** 10 | * Maximum length 11 | */ 12 | maxLength?: number; 13 | }; 14 | 15 | /** 16 | * Initials component 17 | * 18 | * Takes some string and displays the first letter of each word 19 | */ 20 | export function Initials({ input, maxLength }: Props) { 21 | return ( 22 | <> 23 | {input 24 | .split(/\s+/) 25 | .map((x) => x[0]) 26 | .filter((x) => x) 27 | .slice(0, maxLength || 100)} 28 | 29 | ); 30 | } 31 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/LineDivider.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { ComponentStory, ComponentMeta } from "@storybook/react"; 3 | import { Turbo } from "../indicators/Turbo"; 4 | import { LineDivider } from "./LineDivider"; 5 | 6 | export default { 7 | title: "Design System/Atoms/Display/Line Divider", 8 | component: LineDivider, 9 | argTypes: { 10 | /*palette: { 11 | name: "Palette", 12 | control: "radio", 13 | options: ["primary", "accent"], 14 | defaultValue: "primary", 15 | },*/ 16 | turbo: { 17 | name: "Turbo (Demo Content)", 18 | type: "boolean", 19 | defaultValue: false, 20 | }, 21 | }, 22 | } as ComponentMeta; 23 | 24 | const Template: ComponentStory = (args) => ( 25 | {args.turbo && } 26 | ); 27 | 28 | export const Default = Template.bind({}); 29 | 30 | export const WithTurbo = Template.bind({}); 31 | 32 | WithTurbo.args = { turbo: true, palette: "accent" }; 33 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/LineDivider.tsx: -------------------------------------------------------------------------------- 1 | import styled, { css } from "styled-components"; 2 | 3 | export interface Props { 4 | readonly palette?: "primary" | "accent"; 5 | readonly compact?: boolean; 6 | } 7 | 8 | export const LineDivider = styled.div` 9 | display: flex; 10 | margin: ${(props) => (props.compact ? "6px" : "18px")} auto; 11 | user-select: none; 12 | align-items: center; 13 | 14 | height: 1px; 15 | width: calc(100% - 10px); 16 | 17 | ${(props) => 18 | props.palette === "accent" 19 | ? css` 20 | background: var(--accent); 21 | ` 22 | : css` 23 | background: var(--secondary-header); 24 | `} 25 | `; 26 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Modal.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useArgs } from "@storybook/client-api"; 3 | import { ComponentStory, ComponentMeta } from "@storybook/react"; 4 | 5 | import { Modal } from "./Modal"; 6 | 7 | export default { 8 | title: "Design System/Atoms/Display/Modal", 9 | component: Modal, 10 | argTypes: { 11 | open: { 12 | name: "Open", 13 | type: "boolean", 14 | defaultValue: true, 15 | }, 16 | children: { 17 | name: "Content", 18 | type: "string", 19 | defaultValue: 20 | "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.", 21 | }, 22 | title: { 23 | name: "Title", 24 | type: "string", 25 | defaultValue: "Modal Title", 26 | }, 27 | description: { 28 | name: "Description", 29 | type: "string", 30 | defaultValue: "Optional modal description.", 31 | }, 32 | padding: { 33 | name: "Padding", 34 | type: "string", 35 | defaultValue: undefined, 36 | }, 37 | maxWidth: { 38 | name: "Max Width", 39 | type: "string", 40 | defaultValue: undefined, 41 | }, 42 | actions: { 43 | name: "Actions", 44 | defaultValue: [ 45 | { 46 | children: "OK", 47 | palette: "accent", 48 | confirmation: true, 49 | }, 50 | { 51 | children: "Cancel", 52 | palette: "plain", 53 | }, 54 | ], 55 | }, 56 | transparent: { 57 | name: "Transparent", 58 | type: "boolean", 59 | defaultValue: false, 60 | }, 61 | disabled: { 62 | name: "Disabled", 63 | type: "boolean", 64 | defaultValue: false, 65 | }, 66 | nonDismissable: { 67 | name: "Non-dismissable", 68 | type: "boolean", 69 | defaultValue: false, 70 | }, 71 | }, 72 | } as ComponentMeta; 73 | 74 | const Template: ComponentStory = (args) => { 75 | const [_, updateArgs] = useArgs(); 76 | if (!(args as any).open) return <>; 77 | return ( 78 | updateArgs({ open: false })} 81 | registerOnClose={(close) => { 82 | const onKeyUp = (e: KeyboardEvent) => 83 | e.key === "Escape" && close(); 84 | 85 | document.addEventListener("keyup", onKeyUp); 86 | return () => document.removeEventListener("keyup", onKeyUp); 87 | }} 88 | registerOnConfirm={(confirm) => { 89 | const onKeyUp = (e: KeyboardEvent) => { 90 | if (e.key === "Enter") { 91 | confirm(); 92 | updateArgs({ disabled: true }); 93 | setTimeout(close, 1000); 94 | } 95 | }; 96 | 97 | document.addEventListener("keyup", onKeyUp); 98 | return () => document.removeEventListener("keyup", onKeyUp); 99 | }} 100 | /> 101 | ); 102 | }; 103 | 104 | // const Template: ComponentStory = (args) => ; 105 | 106 | export const Default = Template.bind({}); 107 | 108 | export const NoActions = Template.bind({}); 109 | 110 | NoActions.args = { 111 | actions: undefined, 112 | description: undefined, 113 | children: "This modal does not have any actions!", 114 | }; 115 | -------------------------------------------------------------------------------- /src/components/design/atoms/display/Modal.tsx: -------------------------------------------------------------------------------- 1 | import React, { useCallback, useEffect, useState } from "react"; 2 | import { createPortal } from "react-dom"; 3 | import styled, { css } from "styled-components"; 4 | 5 | import { 6 | animationFadeIn, 7 | animationFadeOut, 8 | animationZoomIn, 9 | animationZoomOut, 10 | } from "../../../common/animations"; 11 | 12 | import { H2 } from "../heading/H2"; 13 | import { H4 } from "../heading/H4"; 14 | import { Button, Props as ButtonProps } from "../inputs/Button"; 15 | 16 | export type Action = Omit, "as"> & 17 | Omit & { 18 | confirmation?: boolean; 19 | onClick: () => void | boolean | Promise; 20 | }; 21 | 22 | export interface Props { 23 | padding?: string; 24 | maxWidth?: string; 25 | maxHeight?: string; 26 | 27 | disabled?: boolean; 28 | transparent?: boolean; 29 | nonDismissable?: boolean; 30 | 31 | actions?: Action[]; 32 | onClose?: (force: boolean) => void; 33 | 34 | signal?: "close" | "confirm" | "force"; 35 | registerOnClose?: (fn: () => void) => () => void; 36 | registerOnConfirm?: (fn: () => void) => () => void; 37 | 38 | title?: React.ReactNode; 39 | description?: React.ReactNode; 40 | children?: React.ReactNode; 41 | } 42 | 43 | const Base = styled.div<{ closing?: boolean }>` 44 | top: 0; 45 | left: 0; 46 | width: 100%; 47 | height: 100%; 48 | 49 | z-index: 9999; 50 | position: fixed; 51 | 52 | max-height: 100%; 53 | user-select: none; 54 | 55 | animation-duration: 0.2s; 56 | animation-fill-mode: forwards; 57 | 58 | display: grid; 59 | overflow-y: auto; 60 | place-items: center; 61 | 62 | color: var(--foreground); 63 | background: rgba(0, 0, 0, 0.8); 64 | 65 | ${(props) => 66 | props.closing 67 | ? css` 68 | animation-name: ${animationFadeOut}; 69 | 70 | > div { 71 | animation-name: ${animationZoomOut}; 72 | } 73 | ` 74 | : css` 75 | animation-name: ${animationFadeIn}; 76 | `} 77 | `; 78 | 79 | const Container = styled.div< 80 | Pick & { actions: boolean } 81 | >` 82 | min-height: 200px; 83 | max-width: min(calc(100vw - 20px), ${(props) => props.maxWidth ?? "450px"}); 84 | max-height: min( 85 | calc(100vh - 20px), 86 | ${(props) => props.maxHeight ?? "650px"} 87 | ); 88 | 89 | margin: 20px; 90 | display: flex; 91 | flex-direction: column; 92 | 93 | animation-name: ${animationZoomIn}; 94 | animation-duration: 0.25s; 95 | animation-timing-function: cubic-bezier(0.3, 0.3, 0.18, 1.1); 96 | 97 | ${(props) => 98 | !props.maxWidth && 99 | css` 100 | width: 100%; 101 | `} 102 | 103 | ${(props) => 104 | !props.transparent && 105 | css` 106 | overflow: hidden; 107 | background: var(--secondary-header); 108 | border-radius: var(--border-radius); 109 | `} 110 | `; 111 | 112 | const Title = styled.div` 113 | padding: 1rem; 114 | flex-shrink: 0; 115 | word-break: break-word; 116 | gap: 8px; 117 | display: flex; 118 | flex-direction: column; 119 | `; 120 | 121 | const Content = styled.div>` 122 | flex-grow: 1; 123 | padding-top: 0; 124 | padding: ${(props) => props.padding ?? "0 1rem 1rem"}; 125 | 126 | overflow-y: auto; 127 | font-size: 0.9375rem; 128 | 129 | display: flex; 130 | flex-direction: column; 131 | 132 | ${(props) => 133 | !props.transparent && 134 | css` 135 | background: var(--secondary-header); 136 | `} 137 | `; 138 | 139 | const Actions = styled.div` 140 | flex-shrink: 0; 141 | 142 | gap: 8px; 143 | display: flex; 144 | padding: 1rem; 145 | flex-direction: row-reverse; 146 | 147 | background: var(--secondary-background); 148 | border-radius: 0 0 var(--border-radius) var(--border-radius); 149 | `; 150 | 151 | export const Modal: (props: Props) => JSX.Element = ({ 152 | children, 153 | actions, 154 | disabled, 155 | onClose, 156 | title, 157 | description, 158 | nonDismissable, 159 | registerOnClose, 160 | registerOnConfirm, 161 | signal, 162 | ...props 163 | }: Props) => { 164 | const [closing, setClosing] = useState(false); 165 | 166 | const closeModal = useCallback(() => { 167 | setClosing(true); 168 | if (!closing) setTimeout(() => onClose?.(true), 2e2); 169 | }, [closing, props]); 170 | 171 | const confirm = useCallback(async () => { 172 | if (await actions?.find((x) => x.confirmation)?.onClick?.()) { 173 | closeModal(); 174 | } 175 | }, [actions]); 176 | 177 | useEffect(() => registerOnClose?.(closeModal), [closeModal]); 178 | useEffect(() => registerOnConfirm?.(confirm), [confirm]); 179 | 180 | useEffect(() => { 181 | if (signal === "confirm") { 182 | confirm(); 183 | } else if (signal) { 184 | if (signal === "close" && nonDismissable) { 185 | return; 186 | } 187 | 188 | closeModal(); 189 | } 190 | }, [signal]); 191 | 192 | return createPortal( 193 | !nonDismissable && closeModal()}> 194 | 0 : false} 197 | onClick={(e) => e.stopPropagation()}> 198 | {(title || description) && ( 199 | 200 | {title && <H2>{title}</H2>} 201 | {description && <H4>{description}</H4>} 202 | 203 | )} 204 | {children} 205 | {actions && actions.length > 0 && ( 206 | 207 | {actions.map((x, index) => ( 208 | // @ts-expect-error cope 209 |