@popsure/dirty-swan 0.28.11 → 0.29.0

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.
Files changed (33) hide show
  1. package/dist/cjs/index.js +25 -6
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/lib/components/button/index.d.ts +1 -1
  4. package/dist/cjs/lib/components/modal/index.d.ts +1 -1
  5. package/dist/esm/components/button/index.js +1 -0
  6. package/dist/esm/components/button/index.js.map +1 -1
  7. package/dist/esm/components/input/currency/index.js +15 -3
  8. package/dist/esm/components/input/currency/index.js.map +1 -1
  9. package/dist/esm/components/input/currency/index.test.js +90 -0
  10. package/dist/esm/components/input/currency/index.test.js.map +1 -1
  11. package/dist/esm/components/modal/bottomModal/index.js +6 -2
  12. package/dist/esm/components/modal/bottomModal/index.js.map +1 -1
  13. package/dist/esm/components/modal/bottomOrRegularModal/index.js +1 -0
  14. package/dist/esm/components/modal/bottomOrRegularModal/index.js.map +1 -1
  15. package/dist/esm/components/modal/regularModal/index.js +6 -2
  16. package/dist/esm/components/modal/regularModal/index.js.map +1 -1
  17. package/dist/esm/lib/components/button/index.d.ts +1 -1
  18. package/dist/esm/lib/components/modal/index.d.ts +1 -1
  19. package/dist/index.css +11 -8
  20. package/dist/index.css.map +1 -1
  21. package/dist/lib/scss/private/components/_buttons.scss +5 -0
  22. package/package.json +1 -1
  23. package/src/lib/components/button/index.stories.mdx +21 -0
  24. package/src/lib/components/button/index.tsx +7 -1
  25. package/src/lib/components/input/currency/index.test.tsx +52 -0
  26. package/src/lib/components/input/currency/index.tsx +17 -1
  27. package/src/lib/components/modal/bottomModal/index.tsx +5 -1
  28. package/src/lib/components/modal/bottomModal/style.module.scss +0 -1
  29. package/src/lib/components/modal/index.ts +1 -1
  30. package/src/lib/components/modal/regularModal/index.tsx +6 -2
  31. package/src/lib/components/modal/regularModal/style.module.scss +0 -1
  32. package/src/lib/scss/private/components/_buttons.scss +5 -0
  33. package/src/lib/scss/private/components/button.stories.mdx +16 -0
@@ -53,4 +53,56 @@ describe('Currency input component', () => {
53
53
  await user.type(input, '1234567..34.4');
54
54
  expect(input.value).toBe('1 234 567.34');
55
55
  });
56
+
57
+ it('Should have correct selection start when no spaces are added', async () => {
58
+ const { input, user } = setup();
59
+
60
+ await user.type(input, '123');
61
+ // Should be: 123|
62
+ expect(input.selectionStart).toBe(3);
63
+ });
64
+
65
+ it('Should have correct selection start when spaces are added', async () => {
66
+ const { input, user } = setup();
67
+
68
+ await user.type(input, '1234');
69
+ // Should be: 123 4|
70
+ expect(input.selectionStart).toBe(5);
71
+ });
72
+
73
+ it('Should have correct selection start when typing in middle of input', async () => {
74
+ const { input, user } = setup();
75
+
76
+ await user.type(input, '123{arrowleft}4');
77
+
78
+ // Should be: 1 24|3
79
+ expect(input.selectionStart).toBe(4);
80
+ });
81
+
82
+ it('Should have correct selection start when typing in beginning of input', async () => {
83
+ const { input, user } = setup();
84
+
85
+ await user.type(input, '123{arrowleft}{arrowleft}{arrowleft}4');
86
+
87
+ // Should be: 4 |123
88
+ expect(input.selectionStart).toBe(2);
89
+ });
90
+
91
+ it('Should have correct selection start when typing in input and has currency values', async () => {
92
+ const { input, user } = setup();
93
+
94
+ await user.type(input, '123.2{arrowleft}{arrowleft}{arrowleft}24');
95
+
96
+ // Should be: 12 24|3.2
97
+ expect(input.selectionStart).toBe(5);
98
+ });
99
+
100
+ it('Should have correct selection start when deleting', async () => {
101
+ const { input, user } = setup();
102
+
103
+ await user.type(input, '12345{arrowleft}{backspace}67');
104
+
105
+ // Should be: 123 67|5
106
+ expect(input.selectionStart).toBe(6);
107
+ });
56
108
  });
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from 'react';
1
+ import { useEffect, useRef, useState } from 'react';
2
2
 
3
3
  import { formatInput, reverseFormatInput } from './format';
4
4
  import Input, { InputProps } from '..';
@@ -13,6 +13,8 @@ const CurrencyInput = ({
13
13
  placeholder?: string;
14
14
  onChange?: (value: number) => void;
15
15
  } & Omit<InputProps, 'onChange' | 'value' | 'ref'>) => {
16
+ const inputRef = useRef<HTMLInputElement | null>(null);
17
+ const [cursor, setCursor] = useState<number | null>(null);
16
18
  const [shadowValue, setShadowValue] = useState('');
17
19
 
18
20
  const formattedShadowValue = formatInput(
@@ -37,12 +39,26 @@ const CurrencyInput = ({
37
39
  // eslint-disable-next-line
38
40
  }, [shadowValue]);
39
41
 
42
+ useEffect(() => {
43
+ if (!inputRef.current || !cursor) {
44
+ return;
45
+ }
46
+
47
+ const cursorDiff = String(formattedShadowValue).length - String(shadowValue).length;
48
+ const newCursor = cursorDiff + cursor;
49
+
50
+ inputRef.current.selectionStart = newCursor;
51
+ inputRef.current.selectionEnd = newCursor;
52
+ },[cursor, formattedShadowValue, shadowValue])
53
+
40
54
  return (
41
55
  <Input
42
56
  prefix="€"
57
+ ref={inputRef}
43
58
  type="string"
44
59
  value={formattedShadowValue}
45
60
  onChange={(e) => {
61
+ setCursor(e.target.selectionStart);
46
62
  setShadowValue(e.target.value);
47
63
  }}
48
64
  {...props}
@@ -5,6 +5,7 @@ import styles from './style.module.scss';
5
5
 
6
6
  import imageClose from './img/close.svg';
7
7
  import useOnClose from '../hooks/useOnClose';
8
+ import classNames from 'classnames';
8
9
 
9
10
  export default ({
10
11
  title,
@@ -54,7 +55,10 @@ export default ({
54
55
  style={{ top: `${containerXOffset}px` }}
55
56
  onClick={handleContainerClick}
56
57
  >
57
- <div className={styles.header}>
58
+ <div className={classNames(styles.header, {
59
+ 'jc-between': !!title,
60
+ 'jc-end': !title
61
+ })}>
58
62
  <div className={`p-h4 ${styles.title}`}>{title}</div>
59
63
  {dismissible && (
60
64
  <button
@@ -97,7 +97,6 @@
97
97
  height: 60px;
98
98
 
99
99
  display: flex;
100
- justify-content: space-between;
101
100
  align-items: center;
102
101
 
103
102
  padding: 0 16px;
@@ -3,7 +3,7 @@ import RegularModal from './regularModal';
3
3
  import BottomOrRegularModal from './bottomOrRegularModal';
4
4
 
5
5
  export interface Props {
6
- title: string;
6
+ title?: string;
7
7
  isOpen: boolean;
8
8
  children: React.ReactNode;
9
9
  onClose: () => void;
@@ -6,6 +6,7 @@ import useOnClose from '../hooks/useOnClose';
6
6
  import styles from './style.module.scss';
7
7
 
8
8
  import imageClose from './img/close.svg';
9
+ import classNames from 'classnames';
9
10
 
10
11
  export default ({
11
12
  title,
@@ -44,8 +45,11 @@ export default ({
44
45
  className={styles.body}
45
46
  onClick={handleContainerClick}
46
47
  >
47
- <div className={styles.header}>
48
- <div className={`p-h2 ${styles.title}`}>{title}</div>
48
+ <div className={classNames(styles.header, {
49
+ 'jc-between': !!title,
50
+ 'jc-end': !title
51
+ })}>
52
+ {title && <div className={`p-h2 ${styles.title}`}>{title}</div>}
49
53
  {dismissible && (
50
54
  <button
51
55
  type="button"
@@ -102,7 +102,6 @@
102
102
 
103
103
  .header {
104
104
  display: flex;
105
- justify-content: space-between;
106
105
  align-items: center;
107
106
 
108
107
  padding: 24px 24px 0 24px;
@@ -88,6 +88,11 @@
88
88
  outline: none;
89
89
  box-shadow: 0 0 0 2px rgba($color: $ds-primary-500, $alpha: 0.5);
90
90
  }
91
+
92
+ &-grey {
93
+ @extend .p-btn--secondary;
94
+ background-color: $ds-primary-50;
95
+ }
91
96
  }
92
97
 
93
98
  &--danger {
@@ -52,6 +52,22 @@ You are looking at the css definition of the Button component, if you want you c
52
52
  <button className="p-btn--secondary p-btn--loading">Secondary button</button>
53
53
  </Preview>
54
54
 
55
+ ## Secondary grey button
56
+
57
+ ### Default
58
+
59
+ <Preview>
60
+ <button className="p-btn--secondary-grey">Secondary grey button</button>
61
+ </Preview>
62
+
63
+ ### Disabled
64
+
65
+ <Preview>
66
+ <button className="p-btn--secondary-grey" disabled={true}>
67
+ Secondary grey button
68
+ </button>
69
+ </Preview>
70
+
55
71
  ## Danger button
56
72
 
57
73
  ### Default