ag-common 0.0.547 → 0.0.549

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.
@@ -10,9 +10,5 @@ export interface ISidebar {
10
10
  * optionally pass in SSR cookiedocument
11
11
  */
12
12
  cookieDocument?: string;
13
- /**
14
- * default 15rem
15
- */
16
- width?: string;
17
13
  }
18
- export declare const Sidebar: ({ children, className, key, cookieDocument, width, }: ISidebar) => React.JSX.Element;
14
+ export declare const Sidebar: ({ children, className, key, cookieDocument, }: ISidebar) => React.JSX.Element;
@@ -1,23 +1,59 @@
1
1
  "use strict";
2
2
  'use client';
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
3
26
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
27
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
28
  };
6
29
  Object.defineProperty(exports, "__esModule", { value: true });
7
30
  exports.Sidebar = void 0;
8
31
  const styled_1 = __importDefault(require("@emotion/styled"));
9
- const react_1 = __importDefault(require("react"));
32
+ const react_1 = __importStar(require("react"));
33
+ const helpers_1 = require("../../helpers");
10
34
  const use_1 = require("../../helpers/cookie/use");
11
35
  const common_1 = require("../../styles/common");
36
+ const media_1 = require("../../styles/media");
12
37
  const Chevron_1 = require("../Chevron");
13
38
  const Base = styled_1.default.div `
14
39
  position: relative;
15
40
  transition: all 200ms;
16
41
  border-right: solid 1px #ccc;
17
42
  padding-left: 0.5rem;
18
- //width set in style
43
+ height: 100vh;
19
44
 
45
+ &[data-open='true'] {
46
+ width: 80vw;
47
+ max-width: 30rem;
48
+ @media ${media_1.smallScreen} {
49
+ max-width: unset;
50
+ position: fixed;
51
+ top: 0;
52
+ left: 0;
53
+ }
54
+ }
20
55
  &[data-open='false'] {
56
+ width: 0.5rem;
21
57
  background-color: rgba(0, 0, 0, 0.1);
22
58
  cursor: pointer;
23
59
  &:hover,
@@ -37,14 +73,15 @@ const Base = styled_1.default.div `
37
73
  }
38
74
  `;
39
75
  const ContentBlock = styled_1.default.div `
40
- height: 100%;
41
- left: -18rem;
76
+ left: -30rem;
42
77
  transition: left 200ms;
78
+ height: 100%;
43
79
  &[data-open='false'] {
44
80
  position: absolute;
45
81
  top: 0;
46
82
  z-index: 1;
47
- //width set in style
83
+ width: 80vw;
84
+ max-width: 30rem;
48
85
  }
49
86
  `;
50
87
  const Content = styled_1.default.div `
@@ -56,12 +93,13 @@ const Content = styled_1.default.div `
56
93
  &[data-open='false'] {
57
94
  filter: drop-shadow(1px 1px 0.5rem #555);
58
95
  border-radius: 1rem;
96
+ background-color: rgba(255, 255, 255, 0.1);
59
97
  }
60
98
  `;
61
99
  const Hamburger = styled_1.default.div `
62
100
  position: absolute;
63
101
  transition: all 200ms;
64
- z-index: 1;
102
+ z-index: 2;
65
103
  &[data-open='false'] {
66
104
  top: 0.5rem;
67
105
  left: 0.25rem;
@@ -88,16 +126,23 @@ const ChevronStyled = (0, styled_1.default)(Chevron_1.Chevron) `
88
126
  fill: #555;
89
127
  }
90
128
  `;
91
- const Sidebar = ({ children, className, key = 'sidebar', cookieDocument, width = '15rem', }) => {
129
+ const Sidebar = ({ children, className, key = 'sidebar', cookieDocument, }) => {
130
+ const ref = (0, react_1.useRef)(null);
92
131
  const [open, setOpen] = (0, use_1.useCookieBoolean)({
93
132
  name: key,
94
133
  defaultValue: false,
95
134
  cookieDocument: cookieDocument,
96
135
  });
97
- return (react_1.default.createElement(Base, { "data-type": "sidebar", className: className, "data-open": open, onClick: () => !open && setOpen(true), "data-hover": true, style: { width: !open ? '0.5rem' : width } },
136
+ (0, helpers_1.useOnClickOutside)({ ref }, () => {
137
+ if (!open || window.innerWidth > media_1.smallScreenPx) {
138
+ return;
139
+ }
140
+ setOpen(false);
141
+ });
142
+ return (react_1.default.createElement(Base, { "data-type": "sidebar", className: className, "data-open": open, onClick: () => !open && setOpen(true), "data-hover": true, ref: ref },
98
143
  react_1.default.createElement(Hamburger, { "data-open": open, onClick: () => setOpen(!open), "data-hover": true },
99
144
  react_1.default.createElement(ChevronStyled, { point: open ? 'left' : 'right', width: "100%" })),
100
- react_1.default.createElement(ContentBlock, { "data-type": "content-block", "data-open": open, style: { width: !open ? width : undefined } },
145
+ react_1.default.createElement(ContentBlock, { "data-type": "content-block", "data-open": open },
101
146
  react_1.default.createElement(Content, { "data-type": "content", "data-open": open, onClick: (e) => {
102
147
  e.stopPropagation();
103
148
  } }, children))));
@@ -16,7 +16,7 @@ export declare const Timeline: ({ lineColour, items, onClick, maxCircleSize, cla
16
16
  items: ITimelineItem[];
17
17
  onClick?: ((p: ITimelineItem) => void) | undefined;
18
18
  className?: string | undefined;
19
- /** used for behind icons. default white */
19
+ /** used for behind icons. default inherit */
20
20
  bgColour?: string | undefined;
21
21
  /** if true, will show titles under timeline. default true */
22
22
  showTitles?: boolean | undefined;
@@ -14,6 +14,7 @@ const Icon_1 = require("../Icon");
14
14
  const Base = styled_1.default.div `
15
15
  width: 100%;
16
16
  overflow: hidden;
17
+ background-color: inherit;
17
18
  `;
18
19
  const Row = styled_1.default.div `
19
20
  display: flex;
@@ -24,6 +25,8 @@ const Row = styled_1.default.div `
24
25
  position: relative;
25
26
  width: 100%;
26
27
  height: 100%;
28
+ background-color: inherit;
29
+ z-index: 0;
27
30
  `;
28
31
  const Line = styled_1.default.div `
29
32
  position: absolute;
@@ -34,7 +37,7 @@ const Line = styled_1.default.div `
34
37
  z-index: -1;
35
38
  `;
36
39
  const Item = styled_1.default.div `
37
- background-color: transparent;
40
+ background-color: inherit;
38
41
  width: fit-content;
39
42
  height: 100%;
40
43
  display: flex;
@@ -43,7 +46,7 @@ const Item = styled_1.default.div `
43
46
  const Title = styled_1.default.span `
44
47
  text-align: center;
45
48
  `;
46
- const Timeline = ({ lineColour = '#ccc', items, onClick, maxCircleSize = 'min(5vw,3rem)', className, bgColour = 'white', showTitles = true, }) => {
49
+ const Timeline = ({ lineColour = '#ccc', items, onClick, maxCircleSize = 'min(5vw,3rem)', className, bgColour = 'inherit', showTitles = true, }) => {
47
50
  const firstFalse = items.findIndex((i) => !i.checked && !i.disabled);
48
51
  const lastTrue = (0, array_1.findLastIndex)(items, (i) => i.checked);
49
52
  return (react_1.default.createElement(Base, { className: className },
@@ -1,11 +1,12 @@
1
1
  import type { RefObject } from 'react';
2
2
  type Event = MouseEvent | TouchEvent;
3
3
  export declare function useOnClickOutside<T extends HTMLElement = HTMLElement>(p: {
4
+ ref: RefObject<T>;
4
5
  /**
5
6
  * default false
6
7
  */
7
8
  disabled?: boolean;
8
- ref: RefObject<T>;
9
+ /** if true, will also consider moving mouse outside div. default false */
9
10
  moveMouseOutside?: boolean;
10
11
  }, handler: (event: Event) => void): void;
11
12
  export {};
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.547",
2
+ "version": "0.0.549",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",