@laerdal/life-react-components 1.2.1-dev.1.full → 1.2.1-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/List/ListRow.js +186 -165
- package/dist/esm/List/ListRow.js.map +1 -1
- package/dist/esm/List/__tests__/ListRow.tests.js +6 -48
- package/dist/esm/List/__tests__/ListRow.tests.js.map +1 -1
- package/dist/esm/List/index.js +1 -2
- package/dist/esm/List/index.js.map +1 -1
- package/dist/js/List/ListRow.d.ts +11 -8
- package/dist/js/List/ListRow.js +77 -120
- package/dist/js/List/ListRow.js.map +1 -1
- package/dist/js/List/__tests__/ListRow.tests.js +7 -58
- package/dist/js/List/__tests__/ListRow.tests.js.map +1 -1
- package/dist/js/List/index.d.ts +1 -2
- package/dist/js/List/index.js +0 -8
- package/dist/js/List/index.js.map +1 -1
- package/dist/umd/List/ListRow.js +201 -167
- package/dist/umd/List/ListRow.js.map +1 -1
- package/dist/umd/List/__tests__/ListRow.tests.js +8 -51
- package/dist/umd/List/__tests__/ListRow.tests.js.map +1 -1
- package/dist/umd/List/index.js +5 -8
- package/dist/umd/List/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/esm/List/ListRowDropdown.js +0 -125
- package/dist/esm/List/ListRowDropdown.js.map +0 -1
- package/dist/js/List/ListRowDropdown.d.ts +0 -9
- package/dist/js/List/ListRowDropdown.js +0 -131
- package/dist/js/List/ListRowDropdown.js.map +0 -1
- package/dist/umd/List/ListRowDropdown.js +0 -202
- package/dist/umd/List/ListRowDropdown.js.map +0 -1
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import _pt from "prop-types";
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import styled from 'styled-components';
|
|
4
|
-
import { COLORS, ComponentTextStyle } from '../styles';
|
|
5
|
-
import { ComponentMStyling } from '../styles/typography';
|
|
6
|
-
const Wrapper = styled.div`
|
|
7
|
-
.isInside {
|
|
8
|
-
top: 42px;
|
|
9
|
-
}
|
|
10
|
-
.isOutside {
|
|
11
|
-
bottom: 42px;
|
|
12
|
-
}
|
|
13
|
-
`;
|
|
14
|
-
const DropdownMenuContainer = styled.div`
|
|
15
|
-
position: absolute;
|
|
16
|
-
flex-direction: column;
|
|
17
|
-
background: ${COLORS.white};
|
|
18
|
-
font-size: 1em;
|
|
19
|
-
z-index: 1;
|
|
20
|
-
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
|
|
21
|
-
border-radius: 4px;
|
|
22
|
-
right: 0;
|
|
23
|
-
width: max-content;
|
|
24
|
-
min-width: 260px;
|
|
25
|
-
`;
|
|
26
|
-
const Content = styled.button`
|
|
27
|
-
min-width: 100%;
|
|
28
|
-
padding: 12px 16px;
|
|
29
|
-
|
|
30
|
-
text-align: left;
|
|
31
|
-
height: inherit;
|
|
32
|
-
|
|
33
|
-
${ComponentMStyling(ComponentTextStyle.Regular, COLORS.neutral_600)}
|
|
34
|
-
|
|
35
|
-
background-color: ${COLORS.white};
|
|
36
|
-
border-width: 0;
|
|
37
|
-
|
|
38
|
-
&:hover,
|
|
39
|
-
&:focus {
|
|
40
|
-
cursor: pointer;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
&:hover {
|
|
44
|
-
background: ${COLORS.primary_20};
|
|
45
|
-
border-radius: 4px;
|
|
46
|
-
}
|
|
47
|
-
&:active {
|
|
48
|
-
background: ${COLORS.primary_100};
|
|
49
|
-
border-radius: 4px;
|
|
50
|
-
}
|
|
51
|
-
`;
|
|
52
|
-
const DropdownValue = styled.div`
|
|
53
|
-
height: ${props => handleDropdownHeight(props.size)}
|
|
54
|
-
`;
|
|
55
|
-
|
|
56
|
-
const handleDropdownHeight = size => {
|
|
57
|
-
switch (size) {
|
|
58
|
-
case 'small':
|
|
59
|
-
return '48px;';
|
|
60
|
-
|
|
61
|
-
case 'medium':
|
|
62
|
-
return '56px;';
|
|
63
|
-
|
|
64
|
-
default:
|
|
65
|
-
return '64px;';
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const ListRowDropdown = ({
|
|
70
|
-
options,
|
|
71
|
-
closeDropdown,
|
|
72
|
-
size
|
|
73
|
-
}) => {
|
|
74
|
-
const [classname, setClassname] = React.useState('isInside');
|
|
75
|
-
const reference = React.useRef(null);
|
|
76
|
-
|
|
77
|
-
const clickIsOutside = e => reference && reference?.current && !reference?.current.contains(e.target);
|
|
78
|
-
|
|
79
|
-
const handleClick = e => {
|
|
80
|
-
if (e.keyCode) {
|
|
81
|
-
if (e.keyCode === 27) {
|
|
82
|
-
closeDropdown();
|
|
83
|
-
}
|
|
84
|
-
} else if (clickIsOutside(e)) {
|
|
85
|
-
closeDropdown();
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const isInViewport = (offset = 0) => {
|
|
90
|
-
if (!reference.current) return;
|
|
91
|
-
const top = reference.current.getBoundingClientRect().bottom;
|
|
92
|
-
const inside = top + offset >= 0 && top - offset <= window.innerHeight;
|
|
93
|
-
|
|
94
|
-
if (!inside) {
|
|
95
|
-
setClassname('isOutside');
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
React.useEffect(() => {
|
|
100
|
-
document.addEventListener('mousedown', handleClick, false);
|
|
101
|
-
document.addEventListener('keydown', handleClick, false);
|
|
102
|
-
isInViewport();
|
|
103
|
-
return () => {
|
|
104
|
-
document.removeEventListener('mousedown', handleClick, false);
|
|
105
|
-
document.removeEventListener('keydown', handleClick, false);
|
|
106
|
-
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
107
|
-
}, []);
|
|
108
|
-
return /*#__PURE__*/React.createElement(Wrapper, null, /*#__PURE__*/React.createElement(DropdownMenuContainer, {
|
|
109
|
-
ref: reference,
|
|
110
|
-
className: classname
|
|
111
|
-
}, options.map(option => /*#__PURE__*/React.createElement(DropdownValue, {
|
|
112
|
-
size: size
|
|
113
|
-
}, /*#__PURE__*/React.createElement(Content, {
|
|
114
|
-
key: option.key,
|
|
115
|
-
onClick: option.action
|
|
116
|
-
}, option.label)))));
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
ListRowDropdown.propTypes = {
|
|
120
|
-
options: _pt.array.isRequired,
|
|
121
|
-
closeDropdown: _pt.any.isRequired,
|
|
122
|
-
size: _pt.string.isRequired
|
|
123
|
-
};
|
|
124
|
-
export default ListRowDropdown;
|
|
125
|
-
//# sourceMappingURL=ListRowDropdown.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/List/ListRowDropdown.tsx"],"names":["React","styled","COLORS","ComponentTextStyle","ComponentMStyling","Wrapper","div","DropdownMenuContainer","white","Content","button","Regular","neutral_600","primary_20","primary_100","DropdownValue","props","handleDropdownHeight","size","ListRowDropdown","options","closeDropdown","classname","setClassname","useState","reference","useRef","clickIsOutside","e","current","contains","target","handleClick","keyCode","isInViewport","offset","top","getBoundingClientRect","bottom","inside","window","innerHeight","useEffect","document","addEventListener","removeEventListener","map","option","key","action","label"],"mappings":";AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AACA,OAAOC,MAAP,MAAmB,mBAAnB;AACA,SAAQC,MAAR,EAAgBC,kBAAhB,QAAyC,WAAzC;AAEA,SAAQC,iBAAR,QAAgC,sBAAhC;AAEA,MAAMC,OAAO,GAAGJ,MAAM,CAACK,GAAI;AAC3B;AACA;AACA;AACA;AACA;AACA;AACA,CAPA;AASA,MAAMC,qBAAqB,GAAGN,MAAM,CAACK,GAAI;AACzC;AACA;AACA,gBAAgBJ,MAAM,CAACM,KAAM;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAXA;AAaA,MAAMC,OAAO,GAAGR,MAAM,CAACS,MAAO;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA,IAAIN,iBAAiB,CAACD,kBAAkB,CAACQ,OAApB,EAA6BT,MAAM,CAACU,WAApC,CAAiD;AACtE;AACA,sBAAsBV,MAAM,CAACM,KAAM;AACnC;A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AAG,GAAGX,SAAS,CAACI,OAAV,CAAkBQ,qBAAlB,GAA0CC,MAAtD;AACA,UAAMC,MAAM,GAAGH,GAAG,GAAGD,MAAN,IAAgB,CAAhB,IAAqBC,GAAG,GAAGD,MAAN,IAAgBK,MAAM,CAACC,WAA3D;;AACA,QAAI,CAACF,MAAL,EAAa;AACXhB,MAAAA,YAAY,CAAC,WAAD,CAAZ;AACD;AACF,GAPD;;AASAvB,EAAAA,KAAK,CAAC0C,SAAN,CAAgB,MAAM;AACpBC,IAAAA,QAAQ,CAACC,gBAAT,CAA0B,WAA1B,EAAuCZ,WAAvC,EAAoD,KAApD;AACAW,IAAAA,QAAQ,CAACC,gBAAT,CAA0B,SAA1B,EAAqCZ,WAArC,EAAkD,KAAlD;AACAE,IAAAA,YAAY;AACZ,WAAO,MAAM;AACXS,MAAAA,QAAQ,CAACE,mBAAT,CAA6B,WAA7B,EAA0Cb,WAA1C,EAAuD,KAAvD;AACAW,MAAAA,QAAQ,CAACE,mBAAT,CAA6B,SAA7B,EAAwCb,WAAxC,EAAqD,KAArD;AACD,KAHD,CAJoB,CAQpB;AACD,GATD,EASG,EATH;AAWA,sBACE,oBAAC,OAAD,qBACE,oBAAC,qBAAD;AAAuB,IAAA,GAAG,EAAEP,SAA5B;AAAuC,IAAA,SAAS,EAAEH;AAAlD,KACGF,OAAO,CAAC0B,GAAR,CAAYC,MAAM,iBACjB,oBAAC,aAAD;AAAe,IAAA,IAAI,EAAE7B;AAArB,kBACE,oBAAC,OAAD;AAAS,IAAA,GAAG,EAAE6B,MAAM,CAACC,GAArB;AAA0B,IAAA,OAAO,EAAED,MAAM,CAACE;AAA1C,KACGF,MAAM,CAACG,KADV,CADF,CADD,CADH,CADF,CADF;AAaD,CAjDD;;;AALE9B,EAAAA,O;AACAC,EAAAA,a;AACAH,EAAAA,I;;AAsDF,eAAeC,eAAf","sourcesContent":["import * as React from 'react';\nimport styled from 'styled-components';\nimport {COLORS, ComponentTextStyle} from '../styles';\nimport {ListRowDropdownOption} from '../types';\nimport {ComponentMStyling} from '../styles/typography';\n\nconst Wrapper = styled.div`\n .isInside {\n top: 42px;\n }\n .isOutside {\n bottom: 42px;\n }\n`;\n\nconst DropdownMenuContainer = styled.div`\n position: absolute;\n flex-direction: column;\n background: ${COLORS.white};\n font-size: 1em;\n z-index: 1;\n box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);\n border-radius: 4px;\n right: 0;\n width: max-content;\n min-width: 260px;\n`;\n\nconst Content = styled.button`\n min-width: 100%;\n padding: 12px 16px;\n\n text-align: left;\n height: inherit;\n\n ${ComponentMStyling(ComponentTextStyle.Regular, COLORS.neutral_600)}\n\n background-color: ${COLORS.white};\n border-width: 0;\n\n &:hover,\n &:focus {\n cursor: pointer;\n }\n\n &:hover {\n background: ${COLORS.primary_20};\n border-radius: 4px;\n }\n &:active {\n background: ${COLORS.primary_100};\n border-radius: 4px;\n }\n`;\n\nconst DropdownValue = styled.div<{size:string}>`\n height: ${props=> handleDropdownHeight(props.size)}\n`;\n\nconst handleDropdownHeight = (size:string) => {\n switch(size)\n {\n case 'small' : return '48px;';\n case 'medium' : return '56px;';\n default : return '64px;';\n }\n}\n\ntype DropdownMenuProps = {\n options: ListRowDropdownOption[];\n closeDropdown: any;\n size: string;\n};\n\nconst ListRowDropdown: React.FunctionComponent<DropdownMenuProps> = ({ options, closeDropdown, size }: DropdownMenuProps) => {\n const [classname, setClassname] = React.useState('isInside');\n const reference = React.useRef<HTMLDivElement>(null);\n\n const clickIsOutside = (e: any) => reference && reference?.current && !reference?.current.contains(e.target);\n\n const handleClick = (e: any) => {\n if (e.keyCode) {\n if (e.keyCode === 27) {\n closeDropdown();\n }\n } else if (clickIsOutside(e)) {\n closeDropdown();\n }\n };\n\n const isInViewport = (offset = 0) => {\n if (!reference.current) return;\n const top = reference.current.getBoundingClientRect().bottom;\n const inside = top + offset >= 0 && top - offset <= window.innerHeight;\n if (!inside) {\n setClassname('isOutside');\n }\n };\n\n React.useEffect(() => {\n document.addEventListener('mousedown', handleClick, false);\n document.addEventListener('keydown', handleClick, false);\n isInViewport();\n return () => {\n document.removeEventListener('mousedown', handleClick, false);\n document.removeEventListener('keydown', handleClick, false);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <Wrapper>\n <DropdownMenuContainer ref={reference} className={classname}>\n {options.map(option => (\n <DropdownValue size={size}>\n <Content key={option.key} onClick={option.action} >\n {option.label}\n </Content>\n </DropdownValue>\n ))}\n </DropdownMenuContainer>\n </Wrapper>\n );\n};\n\nexport default ListRowDropdown;\n"],"file":"ListRowDropdown.js"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { ListRowDropdownOption } from '../types';
|
|
3
|
-
declare type DropdownMenuProps = {
|
|
4
|
-
options: ListRowDropdownOption[];
|
|
5
|
-
closeDropdown: any;
|
|
6
|
-
size: string;
|
|
7
|
-
};
|
|
8
|
-
declare const ListRowDropdown: React.FunctionComponent<DropdownMenuProps>;
|
|
9
|
-
export default ListRowDropdown;
|
|
@@ -1,131 +0,0 @@
|
|
|
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 _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
|
-
var React = _interopRequireWildcard(require("react"));
|
|
13
|
-
|
|
14
|
-
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
15
|
-
|
|
16
|
-
var _styles = require("../styles");
|
|
17
|
-
|
|
18
|
-
var _typography = require("../styles/typography");
|
|
19
|
-
|
|
20
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
|
21
|
-
|
|
22
|
-
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); }
|
|
23
|
-
|
|
24
|
-
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; }
|
|
25
|
-
|
|
26
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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 Wrapper = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .isInside {\n top: 42px;\n }\n .isOutside {\n bottom: 42px;\n }\n"])));
|
|
43
|
-
|
|
44
|
-
var DropdownMenuContainer = _styledComponents.default.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: absolute;\n flex-direction: column;\n background: ", ";\n font-size: 1em;\n z-index: 1;\n box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);\n border-radius: 4px;\n right: 0;\n width: max-content;\n min-width: 260px;\n"])), _styles.COLORS.white);
|
|
45
|
-
|
|
46
|
-
var Content = _styledComponents.default.button(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n min-width: 100%;\n padding: 12px 16px;\n\n text-align: left;\n height: inherit;\n\n ", "\n\n background-color: ", ";\n border-width: 0;\n\n &:hover,\n &:focus {\n cursor: pointer;\n }\n\n &:hover {\n background: ", ";\n border-radius: 4px;\n }\n &:active {\n background: ", ";\n border-radius: 4px;\n }\n"])), (0, _typography.ComponentMStyling)(_styles.ComponentTextStyle.Regular, _styles.COLORS.neutral_600), _styles.COLORS.white, _styles.COLORS.primary_20, _styles.COLORS.primary_100);
|
|
47
|
-
|
|
48
|
-
var DropdownValue = _styledComponents.default.div(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n height: ", "\n"])), function (props) {
|
|
49
|
-
return handleDropdownHeight(props.size);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
var handleDropdownHeight = function handleDropdownHeight(size) {
|
|
53
|
-
switch (size) {
|
|
54
|
-
case 'small':
|
|
55
|
-
return '48px;';
|
|
56
|
-
|
|
57
|
-
case 'medium':
|
|
58
|
-
return '56px;';
|
|
59
|
-
|
|
60
|
-
default:
|
|
61
|
-
return '64px;';
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
var ListRowDropdown = function ListRowDropdown(_ref) {
|
|
66
|
-
var options = _ref.options,
|
|
67
|
-
closeDropdown = _ref.closeDropdown,
|
|
68
|
-
size = _ref.size;
|
|
69
|
-
|
|
70
|
-
var _React$useState = React.useState('isInside'),
|
|
71
|
-
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
72
|
-
classname = _React$useState2[0],
|
|
73
|
-
setClassname = _React$useState2[1];
|
|
74
|
-
|
|
75
|
-
var reference = React.useRef(null);
|
|
76
|
-
|
|
77
|
-
var clickIsOutside = function clickIsOutside(e) {
|
|
78
|
-
return reference && (reference === null || reference === void 0 ? void 0 : reference.current) && !(reference !== null && reference !== void 0 && reference.current.contains(e.target));
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
var handleClick = function handleClick(e) {
|
|
82
|
-
if (e.keyCode) {
|
|
83
|
-
if (e.keyCode === 27) {
|
|
84
|
-
closeDropdown();
|
|
85
|
-
}
|
|
86
|
-
} else if (clickIsOutside(e)) {
|
|
87
|
-
closeDropdown();
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
var isInViewport = function isInViewport() {
|
|
92
|
-
var offset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
93
|
-
if (!reference.current) return;
|
|
94
|
-
var top = reference.current.getBoundingClientRect().bottom;
|
|
95
|
-
var inside = top + offset >= 0 && top - offset <= window.innerHeight;
|
|
96
|
-
|
|
97
|
-
if (!inside) {
|
|
98
|
-
setClassname('isOutside');
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
React.useEffect(function () {
|
|
103
|
-
document.addEventListener('mousedown', handleClick, false);
|
|
104
|
-
document.addEventListener('keydown', handleClick, false);
|
|
105
|
-
isInViewport();
|
|
106
|
-
return function () {
|
|
107
|
-
document.removeEventListener('mousedown', handleClick, false);
|
|
108
|
-
document.removeEventListener('keydown', handleClick, false);
|
|
109
|
-
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
110
|
-
}, []);
|
|
111
|
-
return /*#__PURE__*/React.createElement(Wrapper, null, /*#__PURE__*/React.createElement(DropdownMenuContainer, {
|
|
112
|
-
ref: reference,
|
|
113
|
-
className: classname
|
|
114
|
-
}, options.map(function (option) {
|
|
115
|
-
return /*#__PURE__*/React.createElement(DropdownValue, {
|
|
116
|
-
size: size
|
|
117
|
-
}, /*#__PURE__*/React.createElement(Content, {
|
|
118
|
-
key: option.key,
|
|
119
|
-
onClick: option.action
|
|
120
|
-
}, option.label));
|
|
121
|
-
})));
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
ListRowDropdown.propTypes = {
|
|
125
|
-
options: _propTypes.default.array.isRequired,
|
|
126
|
-
closeDropdown: _propTypes.default.any.isRequired,
|
|
127
|
-
size: _propTypes.default.string.isRequired
|
|
128
|
-
};
|
|
129
|
-
var _default = ListRowDropdown;
|
|
130
|
-
exports.default = _default;
|
|
131
|
-
//# sourceMappingURL=ListRowDropdown.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/List/ListRowDropdown.tsx"],"names":["Wrapper","styled","div","DropdownMenuContainer","COLORS","white","Content","button","ComponentTextStyle","Regular","neutral_600","primary_20","primary_100","DropdownValue","props","handleDropdownHeight","size","ListRowDropdown","options","closeDropdown","React","useState","classname","setClassname","reference","useRef","clickIsOutside","e","current","contains","target","handleClick","keyCode","isInViewport","offset","top","getBoundingClientRect","bottom","inside","window","innerHeight","useEffect","document","addEventListener","removeEventListener","map","option","key","action","label"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,OAAO,GAAGC,0BAAOC,GAAV,mJAAb;;AASA,IAAMC,qBAAqB,GAAGF,0BAAOC,GAAV,iTAGXE,eAAOC,KAHI,CAA3B;;AAaA,IAAMC,OAAO,GAAGL,0BAAOM,MAAV,wZAOT,mCAAkBC,2BAAmBC,OAArC,EAA8CL,eAAOM,WAArD,CAPS,EASSN,eAAOC,KAThB,EAkBKD,eAAOO,UAlBZ,EAsBKP,eAAOQ,WAtBZ,CAAb;;AA2BA,IAAMC,aAAa,GAAGZ,0BAAOC,GAAV,0FACP,UAAAY,KAAK;AAAA,SAAGC,oBAAoB,CAACD,KAAK,CAACE,IAAP,CAAvB;AAAA,CADE,CAAnB;;AAIA,IAAMD,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,IAAD,EAAiB;AAC5C,UAAOA,IAAP;AAEE,SAAK,OAAL;AAAe,aAAO,OAAP;;AACf,SAAK,QAAL;AAAgB,aAAO,OAAP;;AAChB;AAAU,aAAO,OAAP;AAJZ;AAMD,CAPD;;AAeA,IAAMC,eAA2D,GAAG,SAA9DA,eAA8D,OAAyD;AAAA,MAAtDC,OAAsD,QAAtDA,OAAsD;AAAA,MAA7CC,aAA6C,QAA7CA,aAA6C;A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AAuCZ,WAAvC,EAAoD,KAApD;AACAW,IAAAA,QAAQ,CAACC,gBAAT,CAA0B,SAA1B,EAAqCZ,WAArC,EAAkD,KAAlD;AACAE,IAAAA,YAAY;AACZ,WAAO,YAAM;AACXS,MAAAA,QAAQ,CAACE,mBAAT,CAA6B,WAA7B,EAA0Cb,WAA1C,EAAuD,KAAvD;AACAW,MAAAA,QAAQ,CAACE,mBAAT,CAA6B,SAA7B,EAAwCb,WAAxC,EAAqD,KAArD;AACD,KAHD,CAJoB,CAQpB;AACD,GATD,EASG,EATH;AAWA,sBACE,oBAAC,OAAD,qBACE,oBAAC,qBAAD;AAAuB,IAAA,GAAG,EAAEP,SAA5B;AAAuC,IAAA,SAAS,EAAEF;AAAlD,KACGJ,OAAO,CAAC2B,GAAR,CAAY,UAAAC,MAAM;AAAA,wBACjB,oBAAC,aAAD;AAAe,MAAA,IAAI,EAAE9B;AAArB,oBACE,oBAAC,OAAD;AAAS,MAAA,GAAG,EAAE8B,MAAM,CAACC,GAArB;AAA0B,MAAA,OAAO,EAAED,MAAM,CAACE;AAA1C,OACGF,MAAM,CAACG,KADV,CADF,CADiB;AAAA,GAAlB,CADH,CADF,CADF;AAaD,CAjDD;;;AALE/B,EAAAA,O;AACAC,EAAAA,a;AACAH,EAAAA,I;;eAsDaC,e","sourcesContent":["import * as React from 'react';\nimport styled from 'styled-components';\nimport {COLORS, ComponentTextStyle} from '../styles';\nimport {ListRowDropdownOption} from '../types';\nimport {ComponentMStyling} from '../styles/typography';\n\nconst Wrapper = styled.div`\n .isInside {\n top: 42px;\n }\n .isOutside {\n bottom: 42px;\n }\n`;\n\nconst DropdownMenuContainer = styled.div`\n position: absolute;\n flex-direction: column;\n background: ${COLORS.white};\n font-size: 1em;\n z-index: 1;\n box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);\n border-radius: 4px;\n right: 0;\n width: max-content;\n min-width: 260px;\n`;\n\nconst Content = styled.button`\n min-width: 100%;\n padding: 12px 16px;\n\n text-align: left;\n height: inherit;\n\n ${ComponentMStyling(ComponentTextStyle.Regular, COLORS.neutral_600)}\n\n background-color: ${COLORS.white};\n border-width: 0;\n\n &:hover,\n &:focus {\n cursor: pointer;\n }\n\n &:hover {\n background: ${COLORS.primary_20};\n border-radius: 4px;\n }\n &:active {\n background: ${COLORS.primary_100};\n border-radius: 4px;\n }\n`;\n\nconst DropdownValue = styled.div<{size:string}>`\n height: ${props=> handleDropdownHeight(props.size)}\n`;\n\nconst handleDropdownHeight = (size:string) => {\n switch(size)\n {\n case 'small' : return '48px;';\n case 'medium' : return '56px;';\n default : return '64px;';\n }\n}\n\ntype DropdownMenuProps = {\n options: ListRowDropdownOption[];\n closeDropdown: any;\n size: string;\n};\n\nconst ListRowDropdown: React.FunctionComponent<DropdownMenuProps> = ({ options, closeDropdown, size }: DropdownMenuProps) => {\n const [classname, setClassname] = React.useState('isInside');\n const reference = React.useRef<HTMLDivElement>(null);\n\n const clickIsOutside = (e: any) => reference && reference?.current && !reference?.current.contains(e.target);\n\n const handleClick = (e: any) => {\n if (e.keyCode) {\n if (e.keyCode === 27) {\n closeDropdown();\n }\n } else if (clickIsOutside(e)) {\n closeDropdown();\n }\n };\n\n const isInViewport = (offset = 0) => {\n if (!reference.current) return;\n const top = reference.current.getBoundingClientRect().bottom;\n const inside = top + offset >= 0 && top - offset <= window.innerHeight;\n if (!inside) {\n setClassname('isOutside');\n }\n };\n\n React.useEffect(() => {\n document.addEventListener('mousedown', handleClick, false);\n document.addEventListener('keydown', handleClick, false);\n isInViewport();\n return () => {\n document.removeEventListener('mousedown', handleClick, false);\n document.removeEventListener('keydown', handleClick, false);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <Wrapper>\n <DropdownMenuContainer ref={reference} className={classname}>\n {options.map(option => (\n <DropdownValue size={size}>\n <Content key={option.key} onClick={option.action} >\n {option.label}\n </Content>\n </DropdownValue>\n ))}\n </DropdownMenuContainer>\n </Wrapper>\n );\n};\n\nexport default ListRowDropdown;\n"],"file":"ListRowDropdown.js"}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
if (typeof define === "function" && define.amd) {
|
|
3
|
-
define(["exports", "prop-types", "react", "styled-components", "../styles", "../styles/typography"], factory);
|
|
4
|
-
} else if (typeof exports !== "undefined") {
|
|
5
|
-
factory(exports, require("prop-types"), require("react"), require("styled-components"), require("../styles"), require("../styles/typography"));
|
|
6
|
-
} else {
|
|
7
|
-
var mod = {
|
|
8
|
-
exports: {}
|
|
9
|
-
};
|
|
10
|
-
factory(mod.exports, global.propTypes, global.react, global.styledComponents, global.styles, global.typography);
|
|
11
|
-
global.undefined = mod.exports;
|
|
12
|
-
}
|
|
13
|
-
})(this, function (exports, _propTypes, _react, _styledComponents, _styles, _typography) {
|
|
14
|
-
"use strict";
|
|
15
|
-
|
|
16
|
-
Object.defineProperty(exports, "__esModule", {
|
|
17
|
-
value: true
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
var _propTypes2 = _interopRequireDefault(_propTypes);
|
|
21
|
-
|
|
22
|
-
var React = _interopRequireWildcard(_react);
|
|
23
|
-
|
|
24
|
-
var _styledComponents2 = _interopRequireDefault(_styledComponents);
|
|
25
|
-
|
|
26
|
-
function _getRequireWildcardCache(nodeInterop) {
|
|
27
|
-
if (typeof WeakMap !== "function") return null;
|
|
28
|
-
var cacheBabelInterop = new WeakMap();
|
|
29
|
-
var cacheNodeInterop = new WeakMap();
|
|
30
|
-
return (_getRequireWildcardCache = function (nodeInterop) {
|
|
31
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
32
|
-
})(nodeInterop);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function _interopRequireWildcard(obj, nodeInterop) {
|
|
36
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
37
|
-
return obj;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
41
|
-
return {
|
|
42
|
-
default: obj
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
var cache = _getRequireWildcardCache(nodeInterop);
|
|
47
|
-
|
|
48
|
-
if (cache && cache.has(obj)) {
|
|
49
|
-
return cache.get(obj);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
var newObj = {};
|
|
53
|
-
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
54
|
-
|
|
55
|
-
for (var key in obj) {
|
|
56
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
57
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
58
|
-
|
|
59
|
-
if (desc && (desc.get || desc.set)) {
|
|
60
|
-
Object.defineProperty(newObj, key, desc);
|
|
61
|
-
} else {
|
|
62
|
-
newObj[key] = obj[key];
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
newObj.default = obj;
|
|
68
|
-
|
|
69
|
-
if (cache) {
|
|
70
|
-
cache.set(obj, newObj);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return newObj;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function _interopRequireDefault(obj) {
|
|
77
|
-
return obj && obj.__esModule ? obj : {
|
|
78
|
-
default: obj
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const Wrapper = _styledComponents2.default.div`
|
|
83
|
-
.isInside {
|
|
84
|
-
top: 42px;
|
|
85
|
-
}
|
|
86
|
-
.isOutside {
|
|
87
|
-
bottom: 42px;
|
|
88
|
-
}
|
|
89
|
-
`;
|
|
90
|
-
const DropdownMenuContainer = _styledComponents2.default.div`
|
|
91
|
-
position: absolute;
|
|
92
|
-
flex-direction: column;
|
|
93
|
-
background: ${_styles.COLORS.white};
|
|
94
|
-
font-size: 1em;
|
|
95
|
-
z-index: 1;
|
|
96
|
-
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
|
|
97
|
-
border-radius: 4px;
|
|
98
|
-
right: 0;
|
|
99
|
-
width: max-content;
|
|
100
|
-
min-width: 260px;
|
|
101
|
-
`;
|
|
102
|
-
const Content = _styledComponents2.default.button`
|
|
103
|
-
min-width: 100%;
|
|
104
|
-
padding: 12px 16px;
|
|
105
|
-
|
|
106
|
-
text-align: left;
|
|
107
|
-
height: inherit;
|
|
108
|
-
|
|
109
|
-
${(0, _typography.ComponentMStyling)(_styles.ComponentTextStyle.Regular, _styles.COLORS.neutral_600)}
|
|
110
|
-
|
|
111
|
-
background-color: ${_styles.COLORS.white};
|
|
112
|
-
border-width: 0;
|
|
113
|
-
|
|
114
|
-
&:hover,
|
|
115
|
-
&:focus {
|
|
116
|
-
cursor: pointer;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
&:hover {
|
|
120
|
-
background: ${_styles.COLORS.primary_20};
|
|
121
|
-
border-radius: 4px;
|
|
122
|
-
}
|
|
123
|
-
&:active {
|
|
124
|
-
background: ${_styles.COLORS.primary_100};
|
|
125
|
-
border-radius: 4px;
|
|
126
|
-
}
|
|
127
|
-
`;
|
|
128
|
-
const DropdownValue = _styledComponents2.default.div`
|
|
129
|
-
height: ${props => handleDropdownHeight(props.size)}
|
|
130
|
-
`;
|
|
131
|
-
|
|
132
|
-
const handleDropdownHeight = size => {
|
|
133
|
-
switch (size) {
|
|
134
|
-
case 'small':
|
|
135
|
-
return '48px;';
|
|
136
|
-
|
|
137
|
-
case 'medium':
|
|
138
|
-
return '56px;';
|
|
139
|
-
|
|
140
|
-
default:
|
|
141
|
-
return '64px;';
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
const ListRowDropdown = ({
|
|
146
|
-
options,
|
|
147
|
-
closeDropdown,
|
|
148
|
-
size
|
|
149
|
-
}) => {
|
|
150
|
-
const [classname, setClassname] = React.useState('isInside');
|
|
151
|
-
const reference = React.useRef(null);
|
|
152
|
-
|
|
153
|
-
const clickIsOutside = e => reference && reference?.current && !reference?.current.contains(e.target);
|
|
154
|
-
|
|
155
|
-
const handleClick = e => {
|
|
156
|
-
if (e.keyCode) {
|
|
157
|
-
if (e.keyCode === 27) {
|
|
158
|
-
closeDropdown();
|
|
159
|
-
}
|
|
160
|
-
} else if (clickIsOutside(e)) {
|
|
161
|
-
closeDropdown();
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const isInViewport = (offset = 0) => {
|
|
166
|
-
if (!reference.current) return;
|
|
167
|
-
const top = reference.current.getBoundingClientRect().bottom;
|
|
168
|
-
const inside = top + offset >= 0 && top - offset <= window.innerHeight;
|
|
169
|
-
|
|
170
|
-
if (!inside) {
|
|
171
|
-
setClassname('isOutside');
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
React.useEffect(() => {
|
|
176
|
-
document.addEventListener('mousedown', handleClick, false);
|
|
177
|
-
document.addEventListener('keydown', handleClick, false);
|
|
178
|
-
isInViewport();
|
|
179
|
-
return () => {
|
|
180
|
-
document.removeEventListener('mousedown', handleClick, false);
|
|
181
|
-
document.removeEventListener('keydown', handleClick, false);
|
|
182
|
-
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
183
|
-
}, []);
|
|
184
|
-
return /*#__PURE__*/React.createElement(Wrapper, null, /*#__PURE__*/React.createElement(DropdownMenuContainer, {
|
|
185
|
-
ref: reference,
|
|
186
|
-
className: classname
|
|
187
|
-
}, options.map(option => /*#__PURE__*/React.createElement(DropdownValue, {
|
|
188
|
-
size: size
|
|
189
|
-
}, /*#__PURE__*/React.createElement(Content, {
|
|
190
|
-
key: option.key,
|
|
191
|
-
onClick: option.action
|
|
192
|
-
}, option.label)))));
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
ListRowDropdown.propTypes = {
|
|
196
|
-
options: _propTypes2.default.array.isRequired,
|
|
197
|
-
closeDropdown: _propTypes2.default.any.isRequired,
|
|
198
|
-
size: _propTypes2.default.string.isRequired
|
|
199
|
-
};
|
|
200
|
-
exports.default = ListRowDropdown;
|
|
201
|
-
});
|
|
202
|
-
//# sourceMappingURL=ListRowDropdown.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/List/ListRowDropdown.tsx"],"names":["Wrapper","styled","div","DropdownMenuContainer","COLORS","white","Content","button","ComponentMStyling","ComponentTextStyle","primary_20","primary_100","DropdownValue","props","handleDropdownHeight","size","options","closeDropdown","ListRowDropdown","React","reference","clickIsOutside","e","handleClick","isInViewport","offset","top","inside","window","setClassname","document","classname","option","action"],"mappings":";;;;;;;;;;;;;;;;;;;;;MAAA,K;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,QAAMA,OAAO,GAAGC,2BAAOC,GAAI;AAC3B;AACA;AACA;AACA;AACA;AACA;AANA,CAAA;AASA,QAAMC,qBAAqB,GAAGF,2BAAOC,GAAI;AACzC;AACA;AACA,gBAAgBE,eAAOC,KAAM;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AAVA,CAAA;AAaA,QAAMC,OAAO,GAAGL,2BAAOM,MAAO;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA,IAAIC,mCAAkBC,2BAAD,OAAjBD,EAA8CJ,eAA7B,WAAjBI,CAAkE;AACtE;AACA,sBAAsBJ,eAAOC,KAAM;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,kBAAkBD,eAAOM,UAAW;AACpC;AACA;AACA;AACA,kBAAkBN,eAAOO,WAAY;AACrC;AACA;AAxBA,CAAA;AA2BA,QAAMC,aAAa,GAAGX,2BAAOC,GAAmB;AAChD,YAAYW,KAAK,IAAGC,oBAAoB,CAACD,KAAK,CAAN,IAAA,CAAa;AADrD,CAAA;;AAIA,QAAMC,oBAAoB,GAAIC,IAAD,IAAiB;AAC5C,YAAA,IAAA;AAEE,WAAA,OAAA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,CAAAA,WAAAA,EAAAA,WAAAA,EAAAA,KAAAA;AACAA,MAAAA,QAAQ,CAARA,gBAAAA,CAAAA,SAAAA,EAAAA,WAAAA,EAAAA,KAAAA;AACAN,MAAAA,YAAY;AACZ,aAAO,MAAM;AACXM,QAAAA,QAAQ,CAARA,mBAAAA,CAAAA,WAAAA,EAAAA,WAAAA,EAAAA,KAAAA;AACAA,QAAAA,QAAQ,CAARA,mBAAAA,CAAAA,SAAAA,EAAAA,WAAAA,EAAAA,KAAAA;AANkB,OAIpB,CAJoB,CAQpB;AARFX,KAAAA,EAAAA,EAAAA;AAWA,WAAA,aACE,KAAA,CAAA,aAAA,CAAA,OAAA,EAAA,IAAA,EAAA,aACE,KAAA,CAAA,aAAA,CAAA,qBAAA,EAAA;AAAuB,MAAA,GAAG,EAA1B,SAAA;AAAuC,MAAA,SAAS,EAAEY;AAAlD,KAAA,EACGf,OAAO,CAAPA,GAAAA,CAAYgB,MAAM,IAAA,aACjB,KAAA,CAAA,aAAA,CAAA,aAAA,EAAA;AAAe,MAAA,IAAI,EAAEjB;AAArB,KAAA,EAAA,aACE,KAAA,CAAA,aAAA,CAAA,OAAA,EAAA;AAAS,MAAA,GAAG,EAAEiB,MAAM,CAApB,GAAA;AAA0B,MAAA,OAAO,EAAEA,MAAM,CAACC;AAA1C,KAAA,EACGD,MAAM,CANnB,KAKU,CADF,CADDhB,CADH,CADF,CADF;AApCF,GAAA;;;AALEA,IAAAA,O;AACAC,IAAAA,a;AACAF,IAAAA,I;;oBAsDF,e","sourcesContent":["import * as React from 'react';\nimport styled from 'styled-components';\nimport {COLORS, ComponentTextStyle} from '../styles';\nimport {ListRowDropdownOption} from '../types';\nimport {ComponentMStyling} from '../styles/typography';\n\nconst Wrapper = styled.div`\n .isInside {\n top: 42px;\n }\n .isOutside {\n bottom: 42px;\n }\n`;\n\nconst DropdownMenuContainer = styled.div`\n position: absolute;\n flex-direction: column;\n background: ${COLORS.white};\n font-size: 1em;\n z-index: 1;\n box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);\n border-radius: 4px;\n right: 0;\n width: max-content;\n min-width: 260px;\n`;\n\nconst Content = styled.button`\n min-width: 100%;\n padding: 12px 16px;\n\n text-align: left;\n height: inherit;\n\n ${ComponentMStyling(ComponentTextStyle.Regular, COLORS.neutral_600)}\n\n background-color: ${COLORS.white};\n border-width: 0;\n\n &:hover,\n &:focus {\n cursor: pointer;\n }\n\n &:hover {\n background: ${COLORS.primary_20};\n border-radius: 4px;\n }\n &:active {\n background: ${COLORS.primary_100};\n border-radius: 4px;\n }\n`;\n\nconst DropdownValue = styled.div<{size:string}>`\n height: ${props=> handleDropdownHeight(props.size)}\n`;\n\nconst handleDropdownHeight = (size:string) => {\n switch(size)\n {\n case 'small' : return '48px;';\n case 'medium' : return '56px;';\n default : return '64px;';\n }\n}\n\ntype DropdownMenuProps = {\n options: ListRowDropdownOption[];\n closeDropdown: any;\n size: string;\n};\n\nconst ListRowDropdown: React.FunctionComponent<DropdownMenuProps> = ({ options, closeDropdown, size }: DropdownMenuProps) => {\n const [classname, setClassname] = React.useState('isInside');\n const reference = React.useRef<HTMLDivElement>(null);\n\n const clickIsOutside = (e: any) => reference && reference?.current && !reference?.current.contains(e.target);\n\n const handleClick = (e: any) => {\n if (e.keyCode) {\n if (e.keyCode === 27) {\n closeDropdown();\n }\n } else if (clickIsOutside(e)) {\n closeDropdown();\n }\n };\n\n const isInViewport = (offset = 0) => {\n if (!reference.current) return;\n const top = reference.current.getBoundingClientRect().bottom;\n const inside = top + offset >= 0 && top - offset <= window.innerHeight;\n if (!inside) {\n setClassname('isOutside');\n }\n };\n\n React.useEffect(() => {\n document.addEventListener('mousedown', handleClick, false);\n document.addEventListener('keydown', handleClick, false);\n isInViewport();\n return () => {\n document.removeEventListener('mousedown', handleClick, false);\n document.removeEventListener('keydown', handleClick, false);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return (\n <Wrapper>\n <DropdownMenuContainer ref={reference} className={classname}>\n {options.map(option => (\n <DropdownValue size={size}>\n <Content key={option.key} onClick={option.action} >\n {option.label}\n </Content>\n </DropdownValue>\n ))}\n </DropdownMenuContainer>\n </Wrapper>\n );\n};\n\nexport default ListRowDropdown;\n"],"file":"ListRowDropdown.js"}
|