@chayns-components/core 5.0.0-beta.2 → 5.0.0-beta.23
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.
- package/lib/components/accordion/Accordion.d.ts +64 -0
- package/lib/components/accordion/Accordion.js +134 -0
- package/lib/components/accordion/Accordion.js.map +1 -0
- package/lib/components/accordion/Accordion.styles.d.ts +6 -0
- package/lib/components/accordion/Accordion.styles.js +40 -0
- package/lib/components/accordion/Accordion.styles.js.map +1 -0
- package/lib/components/accordion/accordion-body/AccordionBody.d.ts +3 -0
- package/lib/components/accordion/accordion-body/AccordionBody.js +36 -0
- package/lib/components/accordion/accordion-body/AccordionBody.js.map +1 -0
- package/lib/components/accordion/accordion-body/AccordionBody.styles.d.ts +1 -0
- package/lib/components/accordion/accordion-body/AccordionBody.styles.js +20 -0
- package/lib/components/accordion/accordion-body/AccordionBody.styles.js.map +1 -0
- package/lib/components/accordion/accordion-content/AccordionContent.d.ts +3 -0
- package/lib/components/accordion/accordion-content/AccordionContent.js +30 -0
- package/lib/components/accordion/accordion-content/AccordionContent.js.map +1 -0
- package/lib/components/accordion/accordion-content/AccordionContent.styles.d.ts +5 -0
- package/lib/components/accordion/accordion-content/AccordionContent.styles.js +25 -0
- package/lib/components/accordion/accordion-content/AccordionContent.styles.js.map +1 -0
- package/lib/components/accordion/accordion-group/AccordionGroup.d.ts +18 -0
- package/lib/components/accordion/accordion-group/AccordionGroup.js +70 -0
- package/lib/components/accordion/accordion-group/AccordionGroup.js.map +1 -0
- package/lib/components/accordion/accordion-head/AccordionHead.d.ts +17 -0
- package/lib/components/accordion/accordion-head/AccordionHead.js +157 -0
- package/lib/components/accordion/accordion-head/AccordionHead.js.map +1 -0
- package/lib/components/accordion/accordion-head/AccordionHead.styles.d.ts +19 -0
- package/lib/components/accordion/accordion-head/AccordionHead.styles.js +77 -0
- package/lib/components/accordion/accordion-head/AccordionHead.styles.js.map +1 -0
- package/lib/components/accordion/accordion-intro/AccordionIntro.d.ts +3 -0
- package/lib/components/accordion/accordion-intro/AccordionIntro.js +24 -0
- package/lib/components/accordion/accordion-intro/AccordionIntro.js.map +1 -0
- package/lib/components/accordion/accordion-intro/AccordionIntro.styles.d.ts +1 -0
- package/lib/components/accordion/accordion-intro/AccordionIntro.styles.js +19 -0
- package/lib/components/accordion/accordion-intro/AccordionIntro.styles.js.map +1 -0
- package/lib/components/accordion/utils.d.ts +11 -0
- package/lib/components/accordion/utils.js +38 -0
- package/lib/components/accordion/utils.js.map +1 -0
- package/lib/components/badge/Badge.d.ts +13 -0
- package/lib/components/badge/Badge.js +28 -0
- package/lib/components/badge/Badge.js.map +1 -0
- package/lib/components/badge/Badge.styles.d.ts +1 -0
- package/lib/components/badge/Badge.styles.js +25 -0
- package/lib/components/badge/Badge.styles.js.map +1 -0
- package/lib/components/button/Button.d.ts +33 -0
- package/lib/components/button/Button.js +51 -0
- package/lib/components/button/Button.js.map +1 -0
- package/lib/components/button/Button.styles.d.ts +7 -0
- package/lib/components/button/Button.styles.js +37 -0
- package/lib/components/button/Button.styles.js.map +1 -0
- package/lib/components/color-scheme-provider/ColorSchemeProvider.d.ts +44 -0
- package/lib/components/color-scheme-provider/ColorSchemeProvider.js +109 -0
- package/lib/components/color-scheme-provider/ColorSchemeProvider.js.map +1 -0
- package/lib/components/context-menu/ContextMenu.d.ts +51 -0
- package/lib/components/context-menu/ContextMenu.js +173 -0
- package/lib/components/context-menu/ContextMenu.js.map +1 -0
- package/lib/components/context-menu/ContextMenu.styles.d.ts +1 -0
- package/lib/components/context-menu/ContextMenu.styles.js +19 -0
- package/lib/components/context-menu/ContextMenu.styles.js.map +1 -0
- package/lib/components/context-menu/constants/alignment.d.ts +8 -0
- package/lib/components/context-menu/constants/alignment.js +18 -0
- package/lib/components/context-menu/constants/alignment.js.map +1 -0
- package/lib/components/context-menu/context-menu-content/ContextMenuContent.d.ts +10 -0
- package/lib/components/context-menu/context-menu-content/ContextMenuContent.js +74 -0
- package/lib/components/context-menu/context-menu-content/ContextMenuContent.js.map +1 -0
- package/lib/components/context-menu/context-menu-content/ContextMenuContent.styles.d.ts +11 -0
- package/lib/components/context-menu/context-menu-content/ContextMenuContent.styles.js +66 -0
- package/lib/components/context-menu/context-menu-content/ContextMenuContent.styles.js.map +1 -0
- package/lib/components/grid-image/GridImage.d.ts +19 -0
- package/lib/components/grid-image/GridImage.js +83 -0
- package/lib/components/grid-image/GridImage.js.map +1 -0
- package/lib/components/grid-image/GridImage.styles.d.ts +21 -0
- package/lib/components/grid-image/GridImage.styles.js +61 -0
- package/lib/components/grid-image/GridImage.styles.js.map +1 -0
- package/lib/components/icon/Icon.d.ts +41 -0
- package/lib/components/icon/Icon.js +86 -0
- package/lib/components/icon/Icon.js.map +1 -0
- package/lib/components/icon/Icon.styles.d.ts +15 -0
- package/lib/components/icon/Icon.styles.js +54 -0
- package/lib/components/icon/Icon.styles.js.map +1 -0
- package/lib/components/icon/utils.d.ts +1 -0
- package/lib/components/icon/utils.js +16 -0
- package/lib/components/icon/utils.js.map +1 -0
- package/lib/components/list/List.d.ts +18 -0
- package/lib/components/list/List.js +91 -0
- package/lib/components/list/List.js.map +1 -0
- package/lib/components/list/list-item/ListItem.d.ts +58 -0
- package/lib/components/list/list-item/ListItem.js +102 -0
- package/lib/components/list/list-item/ListItem.js.map +1 -0
- package/lib/components/list/list-item/ListItem.styles.d.ts +6 -0
- package/lib/components/list/list-item/ListItem.styles.js +38 -0
- package/lib/components/list/list-item/ListItem.styles.js.map +1 -0
- package/lib/components/list/list-item/list-item-body/ListItemBody.d.ts +3 -0
- package/lib/components/list/list-item/list-item-body/ListItemBody.js +39 -0
- package/lib/components/list/list-item/list-item-body/ListItemBody.js.map +1 -0
- package/lib/components/list/list-item/list-item-body/ListItemBody.styles.d.ts +1 -0
- package/lib/components/list/list-item/list-item-body/ListItemBody.styles.js +20 -0
- package/lib/components/list/list-item/list-item-body/ListItemBody.styles.js.map +1 -0
- package/lib/components/list/list-item/list-item-content/ListItemContent.d.ts +3 -0
- package/lib/components/list/list-item/list-item-content/ListItemContent.js +24 -0
- package/lib/components/list/list-item/list-item-content/ListItemContent.js.map +1 -0
- package/lib/components/list/list-item/list-item-content/ListItemContent.styles.d.ts +1 -0
- package/lib/components/list/list-item/list-item-content/ListItemContent.styles.js +22 -0
- package/lib/components/list/list-item/list-item-content/ListItemContent.styles.js.map +1 -0
- package/lib/components/list/list-item/list-item-head/ListItemHead.d.ts +17 -0
- package/lib/components/list/list-item/list-item-head/ListItemHead.js +151 -0
- package/lib/components/list/list-item/list-item-head/ListItemHead.js.map +1 -0
- package/lib/components/list/list-item/list-item-head/ListItemHead.styles.d.ts +30 -0
- package/lib/components/list/list-item/list-item-head/ListItemHead.styles.js +103 -0
- package/lib/components/list/list-item/list-item-head/ListItemHead.styles.js.map +1 -0
- package/lib/hooks/uuid.d.ts +1 -0
- package/lib/hooks/uuid.js +33 -0
- package/lib/hooks/uuid.js.map +1 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +112 -0
- package/lib/index.js.map +1 -0
- package/package.json +63 -61
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StyledIconWrapper = exports.StyledButton = void 0;
|
|
7
|
+
|
|
8
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
9
|
+
|
|
10
|
+
var _templateObject, _templateObject2;
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
15
|
+
|
|
16
|
+
var StyledButton = _styledComponents.default.button(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background-color: ", ";\n border-radius: 3px;\n box-shadow: 1px 2px 3px rgba(0, 0, 0, 0.2);\n border: none;\n color: ", ";\n cursor: pointer;\n display: inline-block;\n line-height: 1.15;\n min-height: 30px;\n opacity: ", ";\n padding: ", ";\n position: relative;\n user-select: none;\n transition: opacity 0.3s ease;\n"])), function (_ref) {
|
|
17
|
+
var isSecondary = _ref.isSecondary,
|
|
18
|
+
theme = _ref.theme;
|
|
19
|
+
return isSecondary ? theme['202'] : theme['408'];
|
|
20
|
+
}, function (_ref2) {
|
|
21
|
+
var isSecondary = _ref2.isSecondary,
|
|
22
|
+
theme = _ref2.theme;
|
|
23
|
+
return isSecondary ? theme.text : 'white';
|
|
24
|
+
}, function (_ref3) {
|
|
25
|
+
var disabled = _ref3.disabled;
|
|
26
|
+
return disabled ? 0.5 : 1;
|
|
27
|
+
}, function (_ref4) {
|
|
28
|
+
var hasIcon = _ref4.hasIcon;
|
|
29
|
+
return "7px 12px 7px ".concat(hasIcon ? '42px' : '12px');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
exports.StyledButton = StyledButton;
|
|
33
|
+
|
|
34
|
+
var StyledIconWrapper = _styledComponents.default.span(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n align-items: center;\n background-color: rgba(255, 255, 255, 0.2);\n bottom: 0;\n display: flex;\n justify-content: center;\n left: 0;\n position: absolute;\n top: 0;\n width: 30px;\n"])));
|
|
35
|
+
|
|
36
|
+
exports.StyledIconWrapper = StyledIconWrapper;
|
|
37
|
+
//# sourceMappingURL=Button.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/button/Button.styles.ts"],"names":["StyledButton","styled","button","isSecondary","theme","text","disabled","hasIcon","StyledIconWrapper","span"],"mappings":";;;;;;;AAAA;;;;;;;;AASO,IAAMA,YAAY,GAAGC,0BAAOC,MAAV,kbACD;AAAA,MAAGC,WAAH,QAAGA,WAAH;AAAA,MAAgBC,KAAhB,QAAgBA,KAAhB;AAAA,SAChBD,WAAW,GAAGC,KAAK,CAAC,KAAD,CAAR,GAAkBA,KAAK,CAAC,KAAD,CADlB;AAAA,CADC,EAMZ;AAAA,MAAGD,WAAH,SAAGA,WAAH;AAAA,MAAgBC,KAAhB,SAAgBA,KAAhB;AAAA,SAAgDD,WAAW,GAAGC,KAAK,CAACC,IAAT,GAAgB,OAA3E;AAAA,CANY,EAWV;AAAA,MAAGC,QAAH,SAAGA,QAAH;AAAA,SAAmBA,QAAQ,GAAG,GAAH,GAAS,CAApC;AAAA,CAXU,EAYV;AAAA,MAAGC,OAAH,SAAGA,OAAH;AAAA,gCAAiCA,OAAO,GAAG,MAAH,GAAY,MAApD;AAAA,CAZU,CAAlB;;;;AAkBA,IAAMC,iBAAiB,GAAGP,0BAAOQ,IAAV,4RAAvB","sourcesContent":["import styled from 'styled-components';\nimport type { ButtonProps } from './Button';\nimport type { WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\n\ntype StyledButtonProps = ButtonProps &\n WithTheme<{\n hasIcon: boolean;\n }>;\n\nexport const StyledButton = styled.button<StyledButtonProps>`\n background-color: ${({ isSecondary, theme }: StyledButtonProps) =>\n isSecondary ? theme['202'] : theme['408']};\n border-radius: 3px;\n box-shadow: 1px 2px 3px rgba(0, 0, 0, 0.2);\n border: none;\n color: ${({ isSecondary, theme }: StyledButtonProps) => (isSecondary ? theme.text : 'white')};\n cursor: pointer;\n display: inline-block;\n line-height: 1.15;\n min-height: 30px;\n opacity: ${({ disabled }) => (disabled ? 0.5 : 1)};\n padding: ${({ hasIcon }) => `7px 12px 7px ${hasIcon ? '42px' : '12px'}`};\n position: relative;\n user-select: none;\n transition: opacity 0.3s ease;\n`;\n\nexport const StyledIconWrapper = styled.span`\n align-items: center;\n background-color: rgba(255, 255, 255, 0.2);\n bottom: 0;\n display: flex;\n justify-content: center;\n left: 0;\n position: absolute;\n top: 0;\n width: 30px;\n`;\n"],"file":"Button.styles.js"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
declare enum ColorMode {
|
|
3
|
+
Classic = 0,
|
|
4
|
+
Dark = 1,
|
|
5
|
+
Light = 2
|
|
6
|
+
}
|
|
7
|
+
declare type ColorSchemeProviderProps = {
|
|
8
|
+
/**
|
|
9
|
+
* The content of the application or the components for which the styles should be set
|
|
10
|
+
*/
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* The hex color to be used for the children
|
|
14
|
+
*/
|
|
15
|
+
color?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The color mode to be used for the children
|
|
18
|
+
*/
|
|
19
|
+
colorMode?: ColorMode;
|
|
20
|
+
/**
|
|
21
|
+
* Css variables to be added in addition to the chayns variables
|
|
22
|
+
*/
|
|
23
|
+
cssVariables?: {
|
|
24
|
+
[key: string]: string | number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The secondary hex color to be used for the children
|
|
28
|
+
*/
|
|
29
|
+
secondaryColor?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Additional styles set on the root element
|
|
32
|
+
*/
|
|
33
|
+
style?: {
|
|
34
|
+
[key: string]: string | number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export interface Theme {
|
|
38
|
+
[key: string]: string;
|
|
39
|
+
}
|
|
40
|
+
export declare type WithTheme<T> = T & {
|
|
41
|
+
theme: Theme;
|
|
42
|
+
};
|
|
43
|
+
declare const ColorSchemeProvider: FC<ColorSchemeProviderProps>;
|
|
44
|
+
export default ColorSchemeProvider;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _colors = require("@chayns/colors");
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
|
|
14
|
+
var _styledComponents = require("styled-components");
|
|
15
|
+
|
|
16
|
+
var _templateObject;
|
|
17
|
+
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
+
|
|
20
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
+
|
|
22
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
+
|
|
24
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
25
|
+
|
|
26
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
+
|
|
28
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
29
|
+
|
|
30
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
31
|
+
|
|
32
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
33
|
+
|
|
34
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
35
|
+
|
|
36
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
37
|
+
|
|
38
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
39
|
+
|
|
40
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
41
|
+
|
|
42
|
+
var ColorMode;
|
|
43
|
+
|
|
44
|
+
(function (ColorMode) {
|
|
45
|
+
ColorMode[ColorMode["Classic"] = 0] = "Classic";
|
|
46
|
+
ColorMode[ColorMode["Dark"] = 1] = "Dark";
|
|
47
|
+
ColorMode[ColorMode["Light"] = 2] = "Light";
|
|
48
|
+
})(ColorMode || (ColorMode = {}));
|
|
49
|
+
|
|
50
|
+
var GlobalStyle = (0, _styledComponents.createGlobalStyle)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .ellipsis {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n"])));
|
|
51
|
+
|
|
52
|
+
var ColorSchemeProvider = function ColorSchemeProvider(_ref) {
|
|
53
|
+
var children = _ref.children,
|
|
54
|
+
_ref$color = _ref.color,
|
|
55
|
+
color = _ref$color === void 0 ? '#005EB8' : _ref$color,
|
|
56
|
+
_ref$colorMode = _ref.colorMode,
|
|
57
|
+
colorMode = _ref$colorMode === void 0 ? ColorMode.Classic : _ref$colorMode,
|
|
58
|
+
_ref$cssVariables = _ref.cssVariables,
|
|
59
|
+
cssVariables = _ref$cssVariables === void 0 ? {} : _ref$cssVariables,
|
|
60
|
+
secondaryColor = _ref.secondaryColor,
|
|
61
|
+
_ref$style = _ref.style,
|
|
62
|
+
style = _ref$style === void 0 ? {} : _ref$style;
|
|
63
|
+
|
|
64
|
+
var _useState = (0, _react.useState)({}),
|
|
65
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
66
|
+
colors = _useState2[0],
|
|
67
|
+
setColors = _useState2[1];
|
|
68
|
+
|
|
69
|
+
var _useState3 = (0, _react.useState)({}),
|
|
70
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
71
|
+
themeColors = _useState4[0],
|
|
72
|
+
setThemeColors = _useState4[1];
|
|
73
|
+
|
|
74
|
+
(0, _react.useEffect)(function () {
|
|
75
|
+
var availableColors = (0, _colors.getAvailableColorList)();
|
|
76
|
+
var newColors = {};
|
|
77
|
+
var newThemeColors = {};
|
|
78
|
+
availableColors.forEach(function (colorName) {
|
|
79
|
+
var hexColor = (0, _colors.getColorFromPalette)(colorName, {
|
|
80
|
+
color: color,
|
|
81
|
+
colorMode: colorMode,
|
|
82
|
+
secondaryColor: secondaryColor
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (hexColor) {
|
|
86
|
+
var rgbColor = (0, _colors.hexToRgb255)(hexColor);
|
|
87
|
+
newColors["--chayns-color--".concat(colorName)] = hexColor;
|
|
88
|
+
newThemeColors[colorName] = hexColor;
|
|
89
|
+
|
|
90
|
+
if (rgbColor) {
|
|
91
|
+
newColors["--chayns-color-rgb--".concat(colorName)] = "".concat(rgbColor.r, ", ").concat(rgbColor.g, ", ").concat(rgbColor.b);
|
|
92
|
+
newThemeColors["".concat(colorName, "-rgb")] = "".concat(rgbColor.r, ", ").concat(rgbColor.g, ", ").concat(rgbColor.b);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
setColors(newColors);
|
|
97
|
+
setThemeColors(newThemeColors);
|
|
98
|
+
}, [color, colorMode, secondaryColor]);
|
|
99
|
+
return /*#__PURE__*/_react.default.createElement(_styledComponents.ThemeProvider, {
|
|
100
|
+
theme: themeColors
|
|
101
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
102
|
+
style: _objectSpread(_objectSpread(_objectSpread({}, colors), cssVariables), style)
|
|
103
|
+
}, children), /*#__PURE__*/_react.default.createElement(GlobalStyle, null));
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
ColorSchemeProvider.displayName = 'ColorSchemeProvider';
|
|
107
|
+
var _default = ColorSchemeProvider;
|
|
108
|
+
exports.default = _default;
|
|
109
|
+
//# sourceMappingURL=ColorSchemeProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/color-scheme-provider/ColorSchemeProvider.tsx"],"names":["ColorMode","GlobalStyle","createGlobalStyle","ColorSchemeProvider","children","color","colorMode","Classic","cssVariables","secondaryColor","style","colors","setColors","themeColors","setThemeColors","availableColors","newColors","newThemeColors","forEach","colorName","hexColor","rgbColor","r","g","b","displayName"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAEKA,S;;WAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;GAAAA,S,KAAAA,S;;AAyCL,IAAMC,WAAW,OAAGC,mCAAH,qLAAjB;;AAQA,IAAMC,mBAAiD,GAAG,SAApDA,mBAAoD,OAOpD;AAAA,MANFC,QAME,QANFA,QAME;AAAA,wBALFC,KAKE;AAAA,MALFA,KAKE,2BALM,SAKN;AAAA,4BAJFC,SAIE;AAAA,MAJFA,SAIE,+BAJUN,SAAS,CAACO,OAIpB;AAAA,+BAHFC,YAGE;AAAA,MAHFA,YAGE,kCAHa,EAGb;AAAA,MAFFC,cAEE,QAFFA,cAEE;AAAA,wBADFC,KACE;AAAA,MADFA,KACE,2BADM,EACN;;AACF,kBAA4B,qBAAgB,EAAhB,CAA5B;AAAA;AAAA,MAAOC,MAAP;AAAA,MAAeC,SAAf;;AACA,mBAAsC,qBAAgB,EAAhB,CAAtC;AAAA;AAAA,MAAOC,WAAP;AAAA,MAAoBC,cAApB;;AAEA,wBAAU,YAAM;AACZ,QAAMC,eAAe,GAAG,oCAAxB;AAEA,QAAMC,SAAgB,GAAG,EAAzB;AACA,QAAMC,cAAqB,GAAG,EAA9B;AAEAF,IAAAA,eAAe,CAACG,OAAhB,CAAwB,UAACC,SAAD,EAAuB;AAC3C,UAAMC,QAAQ,GAAG,iCAAoBD,SAApB,EAA+B;AAC5Cd,QAAAA,KAAK,EAALA,KAD4C;AAE5CC,QAAAA,SAAS,EAATA,SAF4C;AAG5CG,QAAAA,cAAc,EAAdA;AAH4C,OAA/B,CAAjB;;AAMA,UAAIW,QAAJ,EAAc;AACV,YAAMC,QAAQ,GAAG,yBAAYD,QAAZ,CAAjB;AAEAJ,QAAAA,SAAS,2BAAoBG,SAApB,EAAT,GAA4CC,QAA5C;AACAH,QAAAA,cAAc,CAACE,SAAD,CAAd,GAA4BC,QAA5B;;AAEA,YAAIC,QAAJ,EAAc;AACVL,UAAAA,SAAS,+BACkBG,SADlB,EAAT,aAEOE,QAAQ,CAACC,CAFhB,eAEsBD,QAAQ,CAACE,CAF/B,eAEqCF,QAAQ,CAACG,CAF9C;AAGAP,UAAAA,cAAc,WACPE,SADO,UAAd,aAEOE,QAAQ,CAACC,CAFhB,eAEsBD,QAAQ,CAACE,CAF/B,eAEqCF,QAAQ,CAACG,CAF9C;AAGH;AACJ;AACJ,KAtBD;AAwBAZ,IAAAA,SAAS,CAACI,SAAD,CAAT;AACAF,IAAAA,cAAc,CAACG,cAAD,CAAd;AACH,GAhCD,EAgCG,CAACZ,KAAD,EAAQC,SAAR,EAAmBG,cAAnB,CAhCH;AAkCA,sBACI,6BAAC,+BAAD;AAAe,IAAA,KAAK,EAAEI;AAAtB,kBACI;AAAK,IAAA,KAAK,gDAAOF,MAAP,GAAkBH,YAAlB,GAAmCE,KAAnC;AAAV,KAAuDN,QAAvD,CADJ,eAEI,6BAAC,WAAD,OAFJ,CADJ;AAMH,CAnDD;;AAqDAD,mBAAmB,CAACsB,WAApB,GAAkC,qBAAlC;eAEetB,mB","sourcesContent":["import { getAvailableColorList, getColorFromPalette, hexToRgb255 } from '@chayns/colors';\nimport React, { FC, ReactNode, useEffect, useState } from 'react';\nimport { createGlobalStyle, ThemeProvider } from 'styled-components';\n\nenum ColorMode {\n Classic,\n Dark,\n Light,\n}\n\ntype ColorSchemeProviderProps = {\n /**\n * The content of the application or the components for which the styles should be set\n */\n children: ReactNode;\n /**\n * The hex color to be used for the children\n */\n color?: string;\n /**\n * The color mode to be used for the children\n */\n colorMode?: ColorMode;\n /**\n * Css variables to be added in addition to the chayns variables\n */\n cssVariables?: { [key: string]: string | number };\n /**\n * The secondary hex color to be used for the children\n */\n secondaryColor?: string;\n /**\n * Additional styles set on the root element\n */\n style?: { [key: string]: string | number };\n};\n\nexport interface Theme {\n [key: string]: string;\n}\n\nexport type WithTheme<T> = T & {\n theme: Theme;\n};\n\nconst GlobalStyle = createGlobalStyle`\n .ellipsis {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n`;\n\nconst ColorSchemeProvider: FC<ColorSchemeProviderProps> = ({\n children,\n color = '#005EB8',\n colorMode = ColorMode.Classic,\n cssVariables = {},\n secondaryColor,\n style = {},\n}) => {\n const [colors, setColors] = useState<Theme>({});\n const [themeColors, setThemeColors] = useState<Theme>({});\n\n useEffect(() => {\n const availableColors = getAvailableColorList();\n\n const newColors: Theme = {};\n const newThemeColors: Theme = {};\n\n availableColors.forEach((colorName: string) => {\n const hexColor = getColorFromPalette(colorName, {\n color,\n colorMode,\n secondaryColor,\n });\n\n if (hexColor) {\n const rgbColor = hexToRgb255(hexColor);\n\n newColors[`--chayns-color--${colorName}`] = hexColor;\n newThemeColors[colorName] = hexColor;\n\n if (rgbColor) {\n newColors[\n `--chayns-color-rgb--${colorName}`\n ] = `${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b}`;\n newThemeColors[\n `${colorName}-rgb`\n ] = `${rgbColor.r}, ${rgbColor.g}, ${rgbColor.b}`;\n }\n }\n });\n\n setColors(newColors);\n setThemeColors(newThemeColors);\n }, [color, colorMode, secondaryColor]);\n\n return (\n <ThemeProvider theme={themeColors}>\n <div style={{ ...colors, ...cssVariables, ...style }}>{children}</div>\n <GlobalStyle />\n </ThemeProvider>\n );\n};\n\nColorSchemeProvider.displayName = 'ColorSchemeProvider';\n\nexport default ColorSchemeProvider;\n"],"file":"ColorSchemeProvider.js"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React, { MouseEventHandler, ReactNode } from 'react';
|
|
2
|
+
import { ContextMenuAlignment } from './constants/alignment';
|
|
3
|
+
export declare type ContextMenuCoordinates = {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
export declare type ContextMenuItem = {
|
|
8
|
+
icons: string[];
|
|
9
|
+
key: string;
|
|
10
|
+
onClick: MouseEventHandler<HTMLDivElement>;
|
|
11
|
+
text: string;
|
|
12
|
+
};
|
|
13
|
+
declare type ContextMenuRef = {
|
|
14
|
+
hide: VoidFunction;
|
|
15
|
+
show: VoidFunction;
|
|
16
|
+
};
|
|
17
|
+
declare type ContextMenuProps = {
|
|
18
|
+
/**
|
|
19
|
+
* Optional custom alignment used instead of calculating it using the
|
|
20
|
+
* alignment within the page. The available alignment can be taken from the
|
|
21
|
+
* ContextMenuAlignment enum.
|
|
22
|
+
*/
|
|
23
|
+
alignment?: ContextMenuAlignment;
|
|
24
|
+
/**
|
|
25
|
+
* The element over which the content of the `ContextMenu` should be displayed.
|
|
26
|
+
*/
|
|
27
|
+
children?: ReactNode;
|
|
28
|
+
/**
|
|
29
|
+
* The element where the content of the `ContextMenu` should be rendered via React Portal.
|
|
30
|
+
*/
|
|
31
|
+
container?: Element;
|
|
32
|
+
/**
|
|
33
|
+
* Optional own coordinates to be used instead of calculating the alignment
|
|
34
|
+
* based on the alignment of the children.
|
|
35
|
+
*/
|
|
36
|
+
coordinates?: ContextMenuCoordinates;
|
|
37
|
+
/**
|
|
38
|
+
* The items that will be displayed in the content of the `ContextMenu`.
|
|
39
|
+
*/
|
|
40
|
+
items: ContextMenuItem[];
|
|
41
|
+
/**
|
|
42
|
+
* Function to be executed when the content of the Context menu has been hidden.
|
|
43
|
+
*/
|
|
44
|
+
onHide?: VoidFunction;
|
|
45
|
+
/**
|
|
46
|
+
* Function to be executed when the content of the Context menu has been shown.
|
|
47
|
+
*/
|
|
48
|
+
onShow?: VoidFunction;
|
|
49
|
+
};
|
|
50
|
+
declare const ContextMenu: React.ForwardRefExoticComponent<ContextMenuProps & React.RefAttributes<ContextMenuRef>>;
|
|
51
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _framerMotion = require("framer-motion");
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
|
|
14
|
+
var _reactDom = require("react-dom");
|
|
15
|
+
|
|
16
|
+
var _uuid = require("../../hooks/uuid");
|
|
17
|
+
|
|
18
|
+
var _Icon = _interopRequireDefault(require("../icon/Icon"));
|
|
19
|
+
|
|
20
|
+
var _alignment = require("./constants/alignment");
|
|
21
|
+
|
|
22
|
+
var _ContextMenuContent = _interopRequireDefault(require("./context-menu-content/ContextMenuContent"));
|
|
23
|
+
|
|
24
|
+
var _ContextMenu = require("./ContextMenu.styles");
|
|
25
|
+
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
|
|
28
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
|
+
|
|
30
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
|
+
|
|
32
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
33
|
+
|
|
34
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
35
|
+
|
|
36
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
37
|
+
|
|
38
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
39
|
+
|
|
40
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
41
|
+
|
|
42
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
43
|
+
|
|
44
|
+
var ContextMenu = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
45
|
+
var alignment = _ref.alignment,
|
|
46
|
+
_ref$children = _ref.children,
|
|
47
|
+
children = _ref$children === void 0 ? /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
48
|
+
icons: ['ts-ellipsis_v']
|
|
49
|
+
}) : _ref$children,
|
|
50
|
+
_ref$container = _ref.container,
|
|
51
|
+
container = _ref$container === void 0 ? document.body : _ref$container,
|
|
52
|
+
coordinates = _ref.coordinates,
|
|
53
|
+
items = _ref.items,
|
|
54
|
+
onHide = _ref.onHide,
|
|
55
|
+
onShow = _ref.onShow;
|
|
56
|
+
|
|
57
|
+
var _useState = (0, _react.useState)({
|
|
58
|
+
x: 0,
|
|
59
|
+
y: 0
|
|
60
|
+
}),
|
|
61
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
62
|
+
internalCoordinates = _useState2[0],
|
|
63
|
+
setInternalCoordinates = _useState2[1];
|
|
64
|
+
|
|
65
|
+
var _useState3 = (0, _react.useState)(_alignment.ContextMenuAlignment.TopLeft),
|
|
66
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
67
|
+
internalAlignment = _useState4[0],
|
|
68
|
+
setInternalAlignment = _useState4[1];
|
|
69
|
+
|
|
70
|
+
var _useState5 = (0, _react.useState)(false),
|
|
71
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
72
|
+
isContentShown = _useState6[0],
|
|
73
|
+
setIsContentShown = _useState6[1];
|
|
74
|
+
|
|
75
|
+
var uuid = (0, _uuid.useUuid)();
|
|
76
|
+
var contextMenuContentRef = (0, _react.useRef)(null);
|
|
77
|
+
var contextMenuRef = (0, _react.useRef)(null);
|
|
78
|
+
var handleHide = (0, _react.useCallback)(function () {
|
|
79
|
+
setIsContentShown(false);
|
|
80
|
+
}, []);
|
|
81
|
+
var handleShow = (0, _react.useCallback)(function () {
|
|
82
|
+
if (contextMenuRef.current) {
|
|
83
|
+
var rootElement = document.querySelector('.tapp') || document.body;
|
|
84
|
+
|
|
85
|
+
var _contextMenuRef$curre = contextMenuRef.current.getBoundingClientRect(),
|
|
86
|
+
x = _contextMenuRef$curre.x,
|
|
87
|
+
y = _contextMenuRef$curre.y,
|
|
88
|
+
childrenHeight = _contextMenuRef$curre.height,
|
|
89
|
+
childrenWidth = _contextMenuRef$curre.width;
|
|
90
|
+
|
|
91
|
+
setInternalCoordinates({
|
|
92
|
+
x: x + childrenWidth / 2,
|
|
93
|
+
y: y + childrenHeight / 2
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
var _rootElement$getBound = rootElement.getBoundingClientRect(),
|
|
97
|
+
height = _rootElement$getBound.height,
|
|
98
|
+
width = _rootElement$getBound.width;
|
|
99
|
+
|
|
100
|
+
if (x < width / 2) {
|
|
101
|
+
if (y < height / 2) {
|
|
102
|
+
setInternalAlignment(_alignment.ContextMenuAlignment.BottomRight);
|
|
103
|
+
} else {
|
|
104
|
+
setInternalAlignment(_alignment.ContextMenuAlignment.TopRight);
|
|
105
|
+
}
|
|
106
|
+
} else if (y < height / 2) {
|
|
107
|
+
setInternalAlignment(_alignment.ContextMenuAlignment.BottomLeft);
|
|
108
|
+
} else {
|
|
109
|
+
setInternalAlignment(_alignment.ContextMenuAlignment.TopLeft);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
setIsContentShown(true);
|
|
113
|
+
}
|
|
114
|
+
}, []);
|
|
115
|
+
var handleClick = (0, _react.useCallback)(function (event) {
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
event.stopPropagation();
|
|
118
|
+
handleShow();
|
|
119
|
+
}, [handleShow]);
|
|
120
|
+
var handleDocumentClick = (0, _react.useCallback)(function (event) {
|
|
121
|
+
var _contextMenuContentRe;
|
|
122
|
+
|
|
123
|
+
if (!((_contextMenuContentRe = contextMenuContentRef.current) !== null && _contextMenuContentRe !== void 0 && _contextMenuContentRe.contains(event.target))) {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
event.stopPropagation();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
handleHide();
|
|
129
|
+
}, [handleHide]);
|
|
130
|
+
(0, _react.useImperativeHandle)(ref, function () {
|
|
131
|
+
return {
|
|
132
|
+
hide: handleHide,
|
|
133
|
+
show: handleShow
|
|
134
|
+
};
|
|
135
|
+
}, [handleHide, handleShow]);
|
|
136
|
+
(0, _react.useEffect)(function () {
|
|
137
|
+
if (isContentShown) {
|
|
138
|
+
document.addEventListener('click', handleDocumentClick, true);
|
|
139
|
+
window.addEventListener('blur', handleHide);
|
|
140
|
+
|
|
141
|
+
if (typeof onShow === 'function') {
|
|
142
|
+
onShow();
|
|
143
|
+
}
|
|
144
|
+
} else if (typeof onHide === 'function') {
|
|
145
|
+
onHide();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return function () {
|
|
149
|
+
document.removeEventListener('click', handleDocumentClick, true);
|
|
150
|
+
window.removeEventListener('blur', handleHide);
|
|
151
|
+
};
|
|
152
|
+
}, [handleDocumentClick, handleHide, isContentShown, onHide, onShow]);
|
|
153
|
+
var portal = (0, _react.useMemo)(function () {
|
|
154
|
+
return /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react.default.createElement(_framerMotion.AnimatePresence, {
|
|
155
|
+
initial: false
|
|
156
|
+
}, isContentShown && /*#__PURE__*/_react.default.createElement(_ContextMenuContent.default, {
|
|
157
|
+
coordinates: coordinates !== null && coordinates !== void 0 ? coordinates : internalCoordinates,
|
|
158
|
+
items: items,
|
|
159
|
+
key: "contextMenu_".concat(uuid),
|
|
160
|
+
alignment: alignment !== null && alignment !== void 0 ? alignment : internalAlignment,
|
|
161
|
+
ref: contextMenuContentRef
|
|
162
|
+
})), container);
|
|
163
|
+
}, [container, coordinates, internalCoordinates, internalAlignment, isContentShown, items, alignment, uuid]);
|
|
164
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_ContextMenu.StyledContextMenu, {
|
|
165
|
+
className: "beta-chayns-context-menu",
|
|
166
|
+
onClick: handleClick,
|
|
167
|
+
ref: contextMenuRef
|
|
168
|
+
}, children), portal);
|
|
169
|
+
});
|
|
170
|
+
ContextMenu.displayName = 'ContextMenu';
|
|
171
|
+
var _default = ContextMenu;
|
|
172
|
+
exports.default = _default;
|
|
173
|
+
//# sourceMappingURL=ContextMenu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/context-menu/ContextMenu.tsx"],"names":["ContextMenu","ref","alignment","children","container","document","body","coordinates","items","onHide","onShow","x","y","internalCoordinates","setInternalCoordinates","ContextMenuAlignment","TopLeft","internalAlignment","setInternalAlignment","isContentShown","setIsContentShown","uuid","contextMenuContentRef","contextMenuRef","handleHide","handleShow","current","rootElement","querySelector","getBoundingClientRect","childrenHeight","height","childrenWidth","width","BottomRight","TopRight","BottomLeft","handleClick","event","preventDefault","stopPropagation","handleDocumentClick","contains","target","hide","show","addEventListener","window","removeEventListener","portal","displayName"],"mappings":";;;;;;;;;AAAA;;AACA;;AAWA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;AAqDA,IAAMA,WAAW,gBAAG,uBAChB,gBAUIC,GAVJ,EAWK;AAAA,MATGC,SASH,QATGA,SASH;AAAA,2BARGC,QAQH;AAAA,MARGA,QAQH,2CARc,6BAAC,aAAD;AAAM,IAAA,KAAK,EAAE,CAAC,eAAD;AAAb,IAQd;AAAA,4BAPGC,SAOH;AAAA,MAPGA,SAOH,+BAPeC,QAAQ,CAACC,IA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,EAQImB,IARJ,CAhBW,CAAf;AA4BA,sBACI,yEACI,6BAAC,8BAAD;AACI,IAAA,SAAS,EAAC,0BADd;AAEI,IAAA,OAAO,EAAEgB,WAFb;AAGI,IAAA,GAAG,EAAEd;AAHT,KAKKpB,QALL,CADJ,EAQK8C,MARL,CADJ;AAYH,CAvJe,CAApB;AA0JAjD,WAAW,CAACkD,WAAZ,GAA0B,aAA1B;eAEelD,W","sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, {\n forwardRef,\n MouseEventHandler,\n ReactNode,\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { useUuid } from '../../hooks/uuid';\nimport Icon from '../icon/Icon';\nimport { ContextMenuAlignment } from './constants/alignment';\nimport ContextMenuContent from './context-menu-content/ContextMenuContent';\nimport { StyledContextMenu } from './ContextMenu.styles';\n\nexport type ContextMenuCoordinates = {\n x: number;\n y: number;\n};\n\nexport type ContextMenuItem = {\n icons: string[];\n key: string;\n onClick: MouseEventHandler<HTMLDivElement>;\n text: string;\n};\n\ntype ContextMenuRef = {\n hide: VoidFunction;\n show: VoidFunction;\n};\n\ntype ContextMenuProps = {\n /**\n * Optional custom alignment used instead of calculating it using the\n * alignment within the page. The available alignment can be taken from the\n * ContextMenuAlignment enum.\n */\n alignment?: ContextMenuAlignment;\n /**\n * The element over which the content of the `ContextMenu` should be displayed.\n */\n children?: ReactNode;\n /**\n * The element where the content of the `ContextMenu` should be rendered via React Portal.\n */\n container?: Element;\n /**\n * Optional own coordinates to be used instead of calculating the alignment\n * based on the alignment of the children.\n */\n coordinates?: ContextMenuCoordinates;\n /**\n * The items that will be displayed in the content of the `ContextMenu`.\n */\n items: ContextMenuItem[];\n /**\n * Function to be executed when the content of the Context menu has been hidden.\n */\n onHide?: VoidFunction;\n /**\n * Function to be executed when the content of the Context menu has been shown.\n */\n onShow?: VoidFunction;\n};\n\nconst ContextMenu = forwardRef<ContextMenuRef, ContextMenuProps>(\n (\n {\n alignment,\n children = <Icon icons={['ts-ellipsis_v']} />,\n container = document.body,\n coordinates,\n items,\n onHide,\n onShow,\n },\n ref\n ) => {\n const [internalCoordinates, setInternalCoordinates] = useState<ContextMenuCoordinates>({\n x: 0,\n y: 0,\n });\n const [internalAlignment, setInternalAlignment] = useState<ContextMenuAlignment>(\n ContextMenuAlignment.TopLeft\n );\n const [isContentShown, setIsContentShown] = useState(false);\n\n const uuid = useUuid();\n\n const contextMenuContentRef = useRef<HTMLDivElement>(null);\n const contextMenuRef = useRef<HTMLSpanElement>(null);\n\n const handleHide = useCallback(() => {\n setIsContentShown(false);\n }, []);\n\n const handleShow = useCallback(() => {\n if (contextMenuRef.current) {\n const rootElement = document.querySelector('.tapp') || document.body;\n\n const {\n x,\n y,\n height: childrenHeight,\n width: childrenWidth,\n } = contextMenuRef.current.getBoundingClientRect();\n\n setInternalCoordinates({ x: x + childrenWidth / 2, y: y + childrenHeight / 2 });\n\n const { height, width } = rootElement.getBoundingClientRect();\n\n if (x < width / 2) {\n if (y < height / 2) {\n setInternalAlignment(ContextMenuAlignment.BottomRight);\n } else {\n setInternalAlignment(ContextMenuAlignment.TopRight);\n }\n } else if (y < height / 2) {\n setInternalAlignment(ContextMenuAlignment.BottomLeft);\n } else {\n setInternalAlignment(ContextMenuAlignment.TopLeft);\n }\n\n setIsContentShown(true);\n }\n }, []);\n\n const handleClick = useCallback<MouseEventHandler<HTMLDivElement>>(\n (event) => {\n event.preventDefault();\n event.stopPropagation();\n\n handleShow();\n },\n [handleShow]\n );\n\n const handleDocumentClick = useCallback<EventListener>(\n (event) => {\n if (!contextMenuContentRef.current?.contains(event.target as Node)) {\n event.preventDefault();\n event.stopPropagation();\n }\n\n handleHide();\n },\n [handleHide]\n );\n\n useImperativeHandle(\n ref,\n () => ({\n hide: handleHide,\n show: handleShow,\n }),\n [handleHide, handleShow]\n );\n\n useEffect(() => {\n if (isContentShown) {\n document.addEventListener('click', handleDocumentClick, true);\n window.addEventListener('blur', handleHide);\n\n if (typeof onShow === 'function') {\n onShow();\n }\n } else if (typeof onHide === 'function') {\n onHide();\n }\n\n return () => {\n document.removeEventListener('click', handleDocumentClick, true);\n window.removeEventListener('blur', handleHide);\n };\n }, [handleDocumentClick, handleHide, isContentShown, onHide, onShow]);\n\n const portal = useMemo(\n () =>\n createPortal(\n <AnimatePresence initial={false}>\n {isContentShown && (\n <ContextMenuContent\n coordinates={coordinates ?? internalCoordinates}\n items={items}\n key={`contextMenu_${uuid}`}\n alignment={alignment ?? internalAlignment}\n ref={contextMenuContentRef}\n />\n )}\n </AnimatePresence>,\n container\n ),\n [\n container,\n coordinates,\n internalCoordinates,\n internalAlignment,\n isContentShown,\n items,\n alignment,\n uuid,\n ]\n );\n\n return (\n <>\n <StyledContextMenu\n className=\"beta-chayns-context-menu\"\n onClick={handleClick}\n ref={contextMenuRef}\n >\n {children}\n </StyledContextMenu>\n {portal}\n </>\n );\n }\n);\n\nContextMenu.displayName = 'ContextMenu';\n\nexport default ContextMenu;\n"],"file":"ContextMenu.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const StyledContextMenu: import("styled-components").StyledComponent<"span", any, {}, never>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StyledContextMenu = void 0;
|
|
7
|
+
|
|
8
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
9
|
+
|
|
10
|
+
var _templateObject;
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
15
|
+
|
|
16
|
+
var StyledContextMenu = _styledComponents.default.span(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n"])));
|
|
17
|
+
|
|
18
|
+
exports.StyledContextMenu = StyledContextMenu;
|
|
19
|
+
//# sourceMappingURL=ContextMenu.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/context-menu/ContextMenu.styles.ts"],"names":["StyledContextMenu","styled","span"],"mappings":";;;;;;;AAAA;;;;;;;;AAEO,IAAMA,iBAAiB,GAAGC,0BAAOC,IAAV,6FAAvB","sourcesContent":["import styled from 'styled-components';\n\nexport const StyledContextMenu = styled.span`\n cursor: pointer;\n`;\n"],"file":"ContextMenu.styles.js"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ContextMenuAlignment = void 0;
|
|
7
|
+
var ContextMenuAlignment;
|
|
8
|
+
exports.ContextMenuAlignment = ContextMenuAlignment;
|
|
9
|
+
|
|
10
|
+
(function (ContextMenuAlignment) {
|
|
11
|
+
ContextMenuAlignment[ContextMenuAlignment["TopLeft"] = 0] = "TopLeft";
|
|
12
|
+
ContextMenuAlignment[ContextMenuAlignment["BottomLeft"] = 1] = "BottomLeft";
|
|
13
|
+
ContextMenuAlignment[ContextMenuAlignment["TopRight"] = 2] = "TopRight";
|
|
14
|
+
ContextMenuAlignment[ContextMenuAlignment["BottomRight"] = 3] = "BottomRight";
|
|
15
|
+
ContextMenuAlignment[ContextMenuAlignment["TopCenter"] = 4] = "TopCenter";
|
|
16
|
+
ContextMenuAlignment[ContextMenuAlignment["BottomCenter"] = 5] = "BottomCenter";
|
|
17
|
+
})(ContextMenuAlignment || (exports.ContextMenuAlignment = ContextMenuAlignment = {}));
|
|
18
|
+
//# sourceMappingURL=alignment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/context-menu/constants/alignment.ts"],"names":["ContextMenuAlignment"],"mappings":";;;;;;IAAYA,oB;;;WAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;AAAAA,EAAAA,oB,CAAAA,oB;GAAAA,oB,oCAAAA,oB","sourcesContent":["export enum ContextMenuAlignment {\n TopLeft,\n BottomLeft,\n TopRight,\n BottomRight,\n TopCenter,\n BottomCenter,\n}\n"],"file":"alignment.js"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ContextMenuAlignment } from '../constants/alignment';
|
|
3
|
+
import type { ContextMenuCoordinates, ContextMenuItem } from '../ContextMenu';
|
|
4
|
+
declare type ContextMenuContentProps = {
|
|
5
|
+
alignment: ContextMenuAlignment;
|
|
6
|
+
coordinates: ContextMenuCoordinates;
|
|
7
|
+
items: ContextMenuItem[];
|
|
8
|
+
};
|
|
9
|
+
declare const ContextMenuContent: React.ForwardRefExoticComponent<ContextMenuContentProps & React.RefAttributes<HTMLDivElement>>;
|
|
10
|
+
export default ContextMenuContent;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _Icon = _interopRequireDefault(require("../../icon/Icon"));
|
|
11
|
+
|
|
12
|
+
var _alignment = require("../constants/alignment");
|
|
13
|
+
|
|
14
|
+
var _ContextMenuContent = require("./ContextMenuContent.styles");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
var ContextMenuContent = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
19
|
+
var alignment = _ref.alignment,
|
|
20
|
+
coordinates = _ref.coordinates,
|
|
21
|
+
items = _ref.items;
|
|
22
|
+
var isBottomLeftAlignment = alignment === _alignment.ContextMenuAlignment.BottomLeft;
|
|
23
|
+
var isTopLeftAlignment = alignment === _alignment.ContextMenuAlignment.TopLeft;
|
|
24
|
+
var isTopRightAlignment = alignment === _alignment.ContextMenuAlignment.TopRight;
|
|
25
|
+
var percentageOffsetX = isBottomLeftAlignment || isTopLeftAlignment ? -100 : 0;
|
|
26
|
+
var percentageOffsetY = isTopRightAlignment || isTopLeftAlignment ? -100 : 0;
|
|
27
|
+
var anchorOffsetX = isBottomLeftAlignment || isTopLeftAlignment ? 21 : -21;
|
|
28
|
+
var anchorOffsetY = isTopRightAlignment || isTopLeftAlignment ? -21 : 21;
|
|
29
|
+
var exitAndInitialY = isTopLeftAlignment || isTopRightAlignment ? -16 : 16;
|
|
30
|
+
return /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledMotionContextMenuContent, {
|
|
31
|
+
animate: {
|
|
32
|
+
opacity: 1,
|
|
33
|
+
y: 0
|
|
34
|
+
},
|
|
35
|
+
exit: {
|
|
36
|
+
opacity: 0,
|
|
37
|
+
y: exitAndInitialY
|
|
38
|
+
},
|
|
39
|
+
initial: {
|
|
40
|
+
opacity: 0,
|
|
41
|
+
y: exitAndInitialY
|
|
42
|
+
},
|
|
43
|
+
position: alignment,
|
|
44
|
+
ref: ref,
|
|
45
|
+
style: {
|
|
46
|
+
left: coordinates.x,
|
|
47
|
+
top: coordinates.y
|
|
48
|
+
},
|
|
49
|
+
transition: {
|
|
50
|
+
type: 'tween'
|
|
51
|
+
},
|
|
52
|
+
transformTemplate: function transformTemplate(_ref2) {
|
|
53
|
+
var _ref2$y = _ref2.y,
|
|
54
|
+
y = _ref2$y === void 0 ? '0px' : _ref2$y;
|
|
55
|
+
return "\n translateX(".concat(percentageOffsetX, "%)\n translateY(").concat(percentageOffsetY, "%)\n translateX(").concat(anchorOffsetX, "px)\n translateY(").concat(anchorOffsetY, "px)\n translateY(").concat(y, ")\n ");
|
|
56
|
+
}
|
|
57
|
+
}, items.map(function (_ref3) {
|
|
58
|
+
var icons = _ref3.icons,
|
|
59
|
+
key = _ref3.key,
|
|
60
|
+
onClick = _ref3.onClick,
|
|
61
|
+
text = _ref3.text;
|
|
62
|
+
return /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItem, {
|
|
63
|
+
key: key,
|
|
64
|
+
onClick: onClick
|
|
65
|
+
}, /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemIconWrapper, null, /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
|
66
|
+
icons: icons
|
|
67
|
+
})), /*#__PURE__*/_react.default.createElement(_ContextMenuContent.StyledContextMenuContentItemText, null, text));
|
|
68
|
+
}));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
ContextMenuContent.displayName = 'ContextMenuContent';
|
|
72
|
+
var _default = ContextMenuContent;
|
|
73
|
+
exports.default = _default;
|
|
74
|
+
//# sourceMappingURL=ContextMenuContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/context-menu/context-menu-content/ContextMenuContent.tsx"],"names":["ContextMenuContent","React","forwardRef","ref","alignment","coordinates","items","isBottomLeftAlignment","ContextMenuAlignment","BottomLeft","isTopLeftAlignment","TopLeft","isTopRightAlignment","TopRight","percentageOffsetX","percentageOffsetY","anchorOffsetX","anchorOffsetY","exitAndInitialY","opacity","y","left","x","top","type","map","icons","key","onClick","text","displayName"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;AAaA,IAAMA,kBAAkB,gBAAGC,eAAMC,UAAN,CACvB,gBAAoCC,GAApC,EAA4C;AAAA,MAAzCC,SAAyC,QAAzCA,SAAyC;AAAA,MAA9BC,WAA8B,QAA9BA,WAA8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AE;AAAA,0BAAGJ,CAAH;AAAA,UAAGA,CAAH,wBAAO,KAAP;AAAA,wDACFN,iBADE,gDAEFC,iBAFE,gDAGFC,aAHE,iDAIFC,aAJE,iDAKFG,CALE;AAAA;AARvB,KAgBKd,KAAK,CAACmB,GAAN,CAAU;AAAA,QAAGC,KAAH,SAAGA,KAAH;AAAA,QAAUC,GAAV,SAAUA,GAAV;AAAA,QAAeC,OAAf,SAAeA,OAAf;AAAA,QAAwBC,IAAxB,SAAwBA,IAAxB;AAAA,wBACP,6BAAC,gDAAD;AAA8B,MAAA,GAAG,EAAEF,GAAnC;AAAwC,MAAA,OAAO,EAAEC;AAAjD,oBACI,6BAAC,2DAAD,qBACI,6BAAC,aAAD;AAAM,MAAA,KAAK,EAAEF;AAAb,MADJ,CADJ,eAII,6BAAC,oDAAD,QAAmCG,IAAnC,CAJJ,CADO;AAAA,GAAV,CAhBL,CADJ;AA2BH,CAzCsB,CAA3B;;AA4CA7B,kBAAkB,CAAC8B,WAAnB,GAAiC,oBAAjC;eAEe9B,kB","sourcesContent":["import React from 'react';\nimport Icon from '../../icon/Icon';\nimport { ContextMenuAlignment } from '../constants/alignment';\nimport type { ContextMenuCoordinates, ContextMenuItem } from '../ContextMenu';\nimport {\n StyledContextMenuContentItem,\n StyledContextMenuContentItemIconWrapper,\n StyledContextMenuContentItemText,\n StyledMotionContextMenuContent,\n} from './ContextMenuContent.styles';\n\ntype ContextMenuContentProps = {\n alignment: ContextMenuAlignment;\n coordinates: ContextMenuCoordinates;\n items: ContextMenuItem[];\n};\n\nconst ContextMenuContent = React.forwardRef<HTMLDivElement, ContextMenuContentProps>(\n ({ alignment, coordinates, items }, ref) => {\n const isBottomLeftAlignment = alignment === ContextMenuAlignment.BottomLeft;\n const isTopLeftAlignment = alignment === ContextMenuAlignment.TopLeft;\n const isTopRightAlignment = alignment === ContextMenuAlignment.TopRight;\n\n const percentageOffsetX = isBottomLeftAlignment || isTopLeftAlignment ? -100 : 0;\n const percentageOffsetY = isTopRightAlignment || isTopLeftAlignment ? -100 : 0;\n\n const anchorOffsetX = isBottomLeftAlignment || isTopLeftAlignment ? 21 : -21;\n const anchorOffsetY = isTopRightAlignment || isTopLeftAlignment ? -21 : 21;\n\n const exitAndInitialY = isTopLeftAlignment || isTopRightAlignment ? -16 : 16;\n\n return (\n <StyledMotionContextMenuContent\n animate={{ opacity: 1, y: 0 }}\n exit={{ opacity: 0, y: exitAndInitialY }}\n initial={{ opacity: 0, y: exitAndInitialY }}\n position={alignment}\n ref={ref}\n style={{ left: coordinates.x, top: coordinates.y }}\n transition={{ type: 'tween' }}\n transformTemplate={({ y = '0px' }) => `\n translateX(${percentageOffsetX}%)\n translateY(${percentageOffsetY}%)\n translateX(${anchorOffsetX}px)\n translateY(${anchorOffsetY}px)\n translateY(${y})\n `}\n >\n {items.map(({ icons, key, onClick, text }) => (\n <StyledContextMenuContentItem key={key} onClick={onClick}>\n <StyledContextMenuContentItemIconWrapper>\n <Icon icons={icons} />\n </StyledContextMenuContentItemIconWrapper>\n <StyledContextMenuContentItemText>{text}</StyledContextMenuContentItemText>\n </StyledContextMenuContentItem>\n ))}\n </StyledMotionContextMenuContent>\n );\n }\n);\n\nContextMenuContent.displayName = 'ContextMenuContent';\n\nexport default ContextMenuContent;\n"],"file":"ContextMenuContent.js"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ContextMenuAlignment } from '../constants/alignment';
|
|
2
|
+
export declare const StyledMotionContextMenuContent: import("styled-components").StyledComponent<import("framer-motion").ForwardRefComponent<HTMLDivElement, import("framer-motion").HTMLMotionProps<"div">>, any, {
|
|
3
|
+
position: ContextMenuAlignment;
|
|
4
|
+
} & {
|
|
5
|
+
theme: import("../../color-scheme-provider/ColorSchemeProvider").Theme;
|
|
6
|
+
}, never>;
|
|
7
|
+
export declare const StyledContextMenuContentItem: import("styled-components").StyledComponent<"div", any, {
|
|
8
|
+
theme: import("../../color-scheme-provider/ColorSchemeProvider").Theme;
|
|
9
|
+
}, never>;
|
|
10
|
+
export declare const StyledContextMenuContentItemIconWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
11
|
+
export declare const StyledContextMenuContentItemText: import("styled-components").StyledComponent<"div", any, {}, never>;
|