@unitedstatespowersquadrons/components 1.4.5-1 → 1.4.5-3

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.
@@ -1,45 +1,26 @@
1
- import React, { useRef } from "react";
1
+ import React, { useRef, useState } from "react";
2
2
  import { createUseStyles } from "react-jss";
3
- import classNames from "classnames";
4
3
  import AdminItem from "./AdminItem";
5
4
  import { AdminAction, Impersonation as ImpersonationType } from "./types";
6
5
  import ActionButton from "../ActionButton";
7
- import FontAwesomeIcon from "../FontAwesomeIcon";
8
6
  import IconButton from "../IconButton";
9
7
  import Styles from "../Styles";
10
8
  import { OnClickHandler, OnClickOrKeyboardHandler } from "../types";
11
9
 
12
10
  const useStyles = createUseStyles({
13
11
  button: { paddingRight: "0.75em !important" },
14
- center: {
15
- "& svg": { margin: "0 auto" },
16
- justifyContent: "center",
17
- },
18
12
  gray: { ...Styles.gray },
19
13
  impersonation: {
14
+ alignItems: "center",
20
15
  animation: "300ms ease-in",
21
16
  display: "flex",
22
17
  flexDirection: "column",
23
18
  gap: "0.25em",
24
19
  paddingBottom: "0.5em",
20
+ width: "100%",
25
21
  },
26
- inactive: {
27
- "& > div": {
28
- display: "none",
29
- opacity: "0",
30
- transition: "opacity 0.5s ease-in-out",
31
- },
32
- "& > svg": { display: "block" },
33
- "&:hover > div": {
34
- display: "flex",
35
- opacity: "1",
36
- },
37
- "&:hover > svg": { display: "none" },
38
- },
39
- left: { textAlign: "left" },
40
- viewAsIcon: {
41
- ...Styles.purple,
42
- fontSize: "2em",
22
+ triggerIcon: {
23
+ fontSize: "1.5em",
43
24
  },
44
25
  viewingAsIcon: {
45
26
  "&:hover": { ...Styles.hover.red },
@@ -62,6 +43,7 @@ const buildImpersonation = (hooks: Hooks) => {
62
43
  const classes = useStyles();
63
44
 
64
45
  const inputRef = useRef<HTMLInputElement>(null);
46
+ const [expanded, setExpanded] = useState(false);
65
47
 
66
48
  const handleImpersonate: OnClickOrKeyboardHandler = event => {
67
49
  if ("key" in event && event.key !== "Enter") { return; }
@@ -73,10 +55,13 @@ const buildImpersonation = (hooks: Hooks) => {
73
55
  dispatch({ certificate, type: "impersonate" });
74
56
  };
75
57
 
76
- const handleCancel: OnClickHandler = () => {
58
+ const handleCancelImpersonation: OnClickHandler = () => {
77
59
  dispatch({ type: "cancelImpersonation" });
78
60
  };
79
61
 
62
+ const handleExpand: OnClickHandler = () => setExpanded(true);
63
+ const handleCollapse: OnClickHandler = () => setExpanded(false);
64
+
80
65
  if (impersonation) {
81
66
  const { certificate, name } = impersonation;
82
67
 
@@ -87,7 +72,7 @@ const buildImpersonation = (hooks: Hooks) => {
87
72
  className={classes.viewingAsIcon}
88
73
  icon="user-group"
89
74
  mode="duotone"
90
- onClick={handleCancel}
75
+ onClick={handleCancelImpersonation}
91
76
  title="Cancel Impersonation"
92
77
  />
93
78
  <div>{name}</div>
@@ -96,18 +81,32 @@ const buildImpersonation = (hooks: Hooks) => {
96
81
  );
97
82
  }
98
83
 
99
- const collapsed = (
100
- <FontAwesomeIcon
101
- css={classes.viewAsIcon}
102
- icon="user-group"
103
- mode="duotone"
104
- />
105
- );
84
+ if (!expanded) {
85
+ return(
86
+ <AdminItem key="collapsed">
87
+ <IconButton
88
+ className={classes.triggerIcon}
89
+ color="purple"
90
+ icon="user-group"
91
+ mode="duotone"
92
+ onClick={handleExpand}
93
+ title="Impersonate Member"
94
+ />
95
+ </AdminItem>
96
+ );
97
+ }
106
98
 
107
- const expanded = (
108
- <div className={classNames(classes.impersonation, classes.center)}>
99
+ return(
100
+ <AdminItem className={classes.impersonation} key="expanded">
109
101
  <div className="bold">View As:</div>
110
- <FontAwesomeIcon css={classes.viewAsIcon} icon="user-group" mode="duotone" />
102
+ <IconButton
103
+ className={classes.triggerIcon}
104
+ color="purple"
105
+ icon="user-group"
106
+ mode="duotone"
107
+ onClick={handleCollapse}
108
+ title="Collapse"
109
+ />
111
110
  <input
112
111
  maxLength={7}
113
112
  onKeyDown={handleImpersonate}
@@ -124,13 +123,6 @@ const buildImpersonation = (hooks: Hooks) => {
124
123
  size="small"
125
124
  text="Impersonate"
126
125
  />
127
- </div>
128
- );
129
-
130
- return(
131
- <AdminItem className={classes.inactive}>
132
- {collapsed}
133
- {expanded}
134
126
  </AdminItem>
135
127
  );
136
128
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitedstatespowersquadrons/components",
3
- "version": "1.4.5-1",
3
+ "version": "1.4.5-3",
4
4
  "description": "USPS shared React components library",
5
5
  "main": "index.tsx",
6
6
  "scripts": {