pixel-react 1.4.2 → 1.4.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pixel-react",
3
3
  "description": "Great for pixel-perfect, design-focused components in React",
4
- "version": "1.4.2",
4
+ "version": "1.4.3",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.esm.js",
7
7
  "types": "lib/index.d.ts",
@@ -1,10 +1,40 @@
1
- @import url('https://fonts.cdnfonts.com/css/poppins');
2
-
3
1
  @mixin fontPoppins($size: 16px) {
4
2
  font-family: 'Poppins';
5
3
  font-size: $size;
6
4
  }
7
5
 
6
+ @font-face {
7
+ font-family: 'Poppins';
8
+ font-weight: 400;
9
+ src:
10
+ local('Poppins-Regular'),
11
+ url(../../assets/fonts/Poppins-Regular.ttf) format('truetype');
12
+ }
13
+
14
+ @font-face {
15
+ font-family: 'Poppins';
16
+ font-weight: 500;
17
+ src:
18
+ local('Poppins-Medium'),
19
+ url(../../assets/fonts/Poppins-Medium.ttf) format('truetype');
20
+ }
21
+
22
+ @font-face {
23
+ font-family: 'Poppins';
24
+ font-weight: 600;
25
+ src:
26
+ local('Poppins-SemiBold'),
27
+ url(../../assets/fonts/Poppins-SemiBold.ttf) format('truetype');
28
+ }
29
+
30
+ @font-face {
31
+ font-family: 'Poppins';
32
+ font-weight: 700;
33
+ src:
34
+ local('Poppins-Bold'),
35
+ url(../../assets/fonts/Poppins-Bold.ttf) format('truetype');
36
+ }
37
+
8
38
  .fontXs {
9
39
  @include fontPoppins(10px);
10
40
  }
@@ -5,6 +5,7 @@ import Button from '../Button/Button';
5
5
  import './MiniModal.scss';
6
6
  import Typography from '../Typography';
7
7
  import Icon from '../Icon';
8
+ import React from 'react';
8
9
 
9
10
  const meta: Meta<typeof MiniModal> = {
10
11
  title: 'Components/MiniModal',
@@ -41,14 +42,15 @@ const BasicModalComponent = () => {
41
42
  <div className="ff-mini-modal-buttons-flex ff-mini-modal-gap-10">
42
43
  <Button
43
44
  onClick={() => openModal(1)}
45
+ id='112233'
44
46
  ref={btnRef1}
45
- label="1"
47
+ label="122"
46
48
  variant={currentModal === 1 ? 'primary' : 'secondary'}
47
49
  />
48
50
 
49
51
  {currentModal === 1 && (
50
52
  <MiniModal
51
- anchorRef={btnRef1}
53
+ anchorRef="112233"
52
54
  modalProperties={{ width: 300, height: 180 }}
53
55
  headerProps={
54
56
  <>
@@ -254,14 +256,14 @@ export const CustomModalWithArrow = () => {
254
256
  <div className="ff-mini-modal-buttons-flex ff-mini-modal-gap-10">
255
257
  <Button
256
258
  onClick={() => openModal(1)}
257
- ref={btnRef1}
258
- label="1"
259
+ label="12"
260
+ id="1a2b"
259
261
  variant={currentModal === 1 ? 'primary' : 'secondary'}
260
262
  />
261
263
 
262
264
  {currentModal === 1 && (
263
265
  <MiniModal
264
- anchorRef={btnRef1}
266
+ anchorRef='1a2b'
265
267
  modalProperties={{ width: 300, height: 250 }}
266
268
  headerProps={
267
269
  <>
@@ -40,6 +40,7 @@ const MiniModal = forwardRef<HTMLDivElement, MiniEditModalProps>(
40
40
  });
41
41
  const [isVisible, setIsVisible] = useState(false);
42
42
  const modalRef = useRef<HTMLDivElement>(null);
43
+
43
44
  // Function to calculate available space
44
45
  const getAvailableSpace = (rect: Rect): AvailableSpace => {
45
46
  const { top, left, bottom, right } = rect;
@@ -53,7 +54,18 @@ const MiniModal = forwardRef<HTMLDivElement, MiniEditModalProps>(
53
54
  spaceBottom: viewportHeight - bottom,
54
55
  };
55
56
  };
56
- const anchorRect = anchorRef.current?.getBoundingClientRect();
57
+
58
+ // Helper function to get the anchor element
59
+ const getAnchorElement = () => {
60
+ if (typeof anchorRef === 'string') {
61
+ return document.getElementById(anchorRef);
62
+ }
63
+ return anchorRef?.current || null;
64
+ };
65
+
66
+ const anchorElement = getAnchorElement();
67
+ const anchorRect = anchorElement?.getBoundingClientRect();
68
+
57
69
  if (!isWrapped && anchorRect) {
58
70
  const availableSpace = getAvailableSpace(anchorRect);
59
71
  switch (modalPosition) {
@@ -82,7 +94,7 @@ const MiniModal = forwardRef<HTMLDivElement, MiniEditModalProps>(
82
94
  }
83
95
  }
84
96
 
85
- //specify for the wrapper div left position
97
+ // Specify for the wrapper div left position
86
98
  const calculateAnchorRefLeft = (anchorRefLeftNum?: number) => {
87
99
  if (anchorRefLeftNum) {
88
100
  return anchorRefLeftNum;
@@ -90,7 +102,7 @@ const MiniModal = forwardRef<HTMLDivElement, MiniEditModalProps>(
90
102
  return 0;
91
103
  };
92
104
 
93
- //specify for the arrow position in left or top
105
+ // Specify for the arrow position in left or top
94
106
  const getArrowClassName = () => {
95
107
  if (leftTopArrow && modalPosition === 'right') {
96
108
  return 'left-top-arrow';
@@ -99,13 +111,13 @@ const MiniModal = forwardRef<HTMLDivElement, MiniEditModalProps>(
99
111
  };
100
112
  const calculatedAnchorRefLeft = calculateAnchorRefLeft(anchorRefLeftNum);
101
113
 
102
- //specifying for specific wrapper modal position
114
+ // Specify specific wrapper modal position
103
115
  const firstAnchor =
104
116
  firstAnchorRef?.current &&
105
117
  firstAnchorRef?.current?.getBoundingClientRect().left -
106
118
  anchorLeftDistanceForWrapper;
107
119
 
108
- //specifying the modal top
120
+ // Specifying the modal top
109
121
  const calculateModalTop = () => {
110
122
  const safeHeight = modalProperties?.height ?? 0;
111
123
  if (modalPosition === 'bottom') {
@@ -115,24 +127,18 @@ const MiniModal = forwardRef<HTMLDivElement, MiniEditModalProps>(
115
127
  } else if (modalPosition === 'right') {
116
128
  return leftTopArrow
117
129
  ? modalPositionState.top - (extraRightSpace?.leftTopArrow ?? 30)
118
- : modalPositionState?.top -
119
- safeHeight / (extraRightSpace?.middleLeftArrow ?? 3.5);
130
+ : modalPositionState?.top - safeHeight / (extraRightSpace?.middleLeftArrow ?? 3.5);
120
131
  } else if (modalPosition === 'top') {
121
- return (
122
- modalPositionState.top -
123
- (safeHeight + (extraTopSpace?.normalModal ?? 10))
124
- );
132
+ return modalPositionState.top - (safeHeight + (extraTopSpace?.normalModal ?? 10));
125
133
  }
126
134
  return modalPositionState.top - safeHeight / 1.5;
127
135
  };
128
136
  const calculatedModalTop = calculateModalTop();
129
137
 
130
- //specifying the modal left
138
+ // Specifying the modal left
131
139
  const calculateModalLeft = () => {
132
140
  if (modalPosition === 'right') {
133
- return (
134
- modalPositionState.left + (extraLeftSpace?.rightAlignModal ?? 40)
135
- );
141
+ return modalPositionState.left + (extraLeftSpace?.rightAlignModal ?? 40);
136
142
  } else if (firstAnchorRef) {
137
143
  return firstAnchor;
138
144
  } else if (modalPosition === 'left') {
@@ -143,16 +149,16 @@ const MiniModal = forwardRef<HTMLDivElement, MiniEditModalProps>(
143
149
  };
144
150
  const calculatedModalLeft = calculateModalLeft();
145
151
 
146
- //specifying the modal's escape and enter functionality
152
+ // Handle escape and enter functionality
147
153
  const handleEsc = useEscapeKey('Escape');
148
154
  const handleEnter = useEscapeKey('Enter');
149
155
  handleEsc(cancelButtonProps?.onClick);
150
156
  handleEnter(proceedButtonProps?.onClick);
151
157
  useClickOutside(modalRef, cancelButtonProps.onClick);
152
158
 
153
- //calculate the modal position
159
+ // Calculate the modal position
154
160
  const calculatePosition = useCallback(() => {
155
- const anchorRect = anchorRef.current?.getBoundingClientRect();
161
+ const anchorRect = anchorElement?.getBoundingClientRect();
156
162
  if (anchorRect) {
157
163
  const { bottom, left } = anchorRect;
158
164
  const { scrollX, scrollY } = window;
@@ -164,7 +170,7 @@ const MiniModal = forwardRef<HTMLDivElement, MiniEditModalProps>(
164
170
  left: leftPosition,
165
171
  });
166
172
  }
167
- }, [anchorRef, modalProperties]);
173
+ }, [anchorElement]);
168
174
 
169
175
  useEffect(() => {
170
176
  const timeoutId = setTimeout(() => {
@@ -213,10 +219,10 @@ const MiniModal = forwardRef<HTMLDivElement, MiniEditModalProps>(
213
219
  modalPosition === 'right'
214
220
  ? 'left'
215
221
  : modalPosition === 'top'
216
- ? 'bottom'
217
- : modalPosition === 'left'
218
- ? 'right'
219
- : 'top'
222
+ ? 'bottom'
223
+ : modalPosition === 'left'
224
+ ? 'right'
225
+ : 'top'
220
226
  } ${getArrowClassName()}`}
221
227
  />
222
228
  )}
@@ -9,7 +9,7 @@ export interface MiniEditModalProps {
9
9
  /**
10
10
  * A reference to the button element that triggers the modal.
11
11
  */
12
- anchorRef: RefObject<HTMLButtonElement>;
12
+ anchorRef: RefObject<HTMLButtonElement> | string;
13
13
  /**
14
14
  * Optional properties for configuring the modal header.
15
15
  */
@@ -1,10 +1,40 @@
1
- @import url('https://fonts.cdnfonts.com/css/poppins');
2
-
3
1
  @mixin fontPoppins($size: 16px) {
4
2
  font-family: 'Poppins';
5
3
  font-size: $size;
6
4
  }
7
5
 
6
+ @font-face {
7
+ font-family: 'Poppins';
8
+ font-weight: 400;
9
+ src:
10
+ local('Poppins-Regular'),
11
+ url(../../fonts/Poppins/Poppins-Regular.ttf) format('truetype');
12
+ }
13
+
14
+ @font-face {
15
+ font-family: 'Poppins';
16
+ font-weight: 500;
17
+ src:
18
+ local('Poppins-Medium'),
19
+ url(../../fonts/Poppins/Poppins-Medium.ttf) format('truetype');
20
+ }
21
+
22
+ @font-face {
23
+ font-family: 'Poppins';
24
+ font-weight: 600;
25
+ src:
26
+ local('Poppins-SemiBold'),
27
+ url(../../fonts/Poppins/Poppins-SemiBold.ttf) format('truetype');
28
+ }
29
+
30
+ @font-face {
31
+ font-family: 'Poppins';
32
+ font-weight: 700;
33
+ src:
34
+ local('Poppins-Bold'),
35
+ url(../../fonts/Poppins/Poppins-Bold.ttf) format('truetype');
36
+ }
37
+
8
38
  .ff-text {
9
39
  @include fontPoppins();
10
40