@ssa-ui-kit/core 0.0.14-alpha → 0.0.16-alpha

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssa-ui-kit/core",
3
- "version": "0.0.14-alpha",
3
+ "version": "0.0.16-alpha",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "private": false,
@@ -2,6 +2,7 @@ import { Meta, StoryObj } from '@storybook/react';
2
2
  import { css, useTheme } from '@emotion/react';
3
3
  import { ButtonGroup } from './ButtonGroup';
4
4
  import { items } from './helpers';
5
+ import { ExternalStateStory } from './stories/ExternalState';
5
6
 
6
7
  export default {
7
8
  title: 'Components/ButtonGroup',
@@ -14,6 +15,12 @@ export const Default: StoryObj<typeof ButtonGroup> = () => {
14
15
 
15
16
  Default.args = {};
16
17
 
18
+ export const ExternalState: StoryObj<typeof ButtonGroup> = () => {
19
+ return <ExternalStateStory />;
20
+ };
21
+
22
+ ExternalState.args = {};
23
+
17
24
  export const CustomStyle: StoryObj<typeof ButtonGroup> = () => {
18
25
  const theme = useTheme();
19
26
  return (
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import Button from '@components/Button';
3
3
  import Typography from '@components/Typography';
4
4
  import { ButtonGroupProps, ButtonGroupItem } from './types';
@@ -8,6 +8,7 @@ export const ButtonGroup = ({
8
8
  items,
9
9
  buttonStyles,
10
10
  selectedItem,
11
+ externalState = selectedItem || items[0],
11
12
  onClick,
12
13
  }: ButtonGroupProps) => {
13
14
  const [activeBtn, setActiveBtn] = useState(selectedItem || items[0]);
@@ -16,6 +17,10 @@ export const ButtonGroup = ({
16
17
  onClick(item);
17
18
  };
18
19
 
20
+ useEffect(() => {
21
+ setActiveBtn(externalState);
22
+ }, [externalState]);
23
+
19
24
  return (
20
25
  <React.Fragment>
21
26
  {items.map((item) => {
@@ -0,0 +1,60 @@
1
+ import { useState } from 'react';
2
+ import { ButtonGroup } from '../ButtonGroup';
3
+ import { items } from '../helpers';
4
+ import { ButtonGroupItem } from '../types';
5
+
6
+ export const ExternalStateStory = () => {
7
+ const [externalState, setExternalState] = useState<ButtonGroupItem>();
8
+ const handleExternalClick = () => {
9
+ setExternalState(items[2]);
10
+ };
11
+ const handleClick = (item: ButtonGroupItem) => () => {
12
+ setExternalState(item);
13
+ };
14
+ return (
15
+ <div
16
+ css={{
17
+ display: 'flex',
18
+ flexDirection: 'column',
19
+ width: 250,
20
+ gap: 10,
21
+ alignItems: 'center',
22
+ justifyContent: 'center',
23
+ }}>
24
+ <div
25
+ css={{
26
+ width: 250,
27
+ display: 'flex',
28
+ flexDirection: 'row',
29
+ alignItems: 'center',
30
+ gap: 5,
31
+ }}>
32
+ <ButtonGroup
33
+ items={items}
34
+ onClick={(item) => handleClick(item)()}
35
+ externalState={externalState}
36
+ />
37
+ </div>
38
+ <button
39
+ type="button"
40
+ onClick={handleExternalClick}
41
+ css={{
42
+ border: 'none',
43
+ background: '#eef1f7',
44
+ padding: 8,
45
+ cursor: 'pointer',
46
+ '&:hover': {
47
+ background: '#fff',
48
+ },
49
+ '&:focus': {
50
+ background: 'rgb(222, 225, 236)',
51
+ },
52
+ '&:active': {
53
+ background: 'rgb(210, 212, 219)',
54
+ },
55
+ }}>
56
+ Choose &quot;Stopped&quot; tab
57
+ </button>
58
+ </div>
59
+ );
60
+ };
@@ -9,6 +9,7 @@ export type ButtonGroupItem = {
9
9
  export interface ButtonGroupProps {
10
10
  items: Array<ButtonGroupItem>;
11
11
  selectedItem?: ButtonGroupItem;
12
+ externalState?: ButtonGroupItem;
12
13
  onClick: (item: ButtonGroupItem) => void;
13
14
  buttonStyles?: SerializedStyles;
14
15
  }
@@ -14,6 +14,7 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
14
14
  rows = 10,
15
15
  maxLength,
16
16
  title,
17
+ onPaste,
17
18
  register,
18
19
  setCountChar,
19
20
  }: TextareaProps,
@@ -33,6 +34,7 @@ const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
33
34
  rows={rows}
34
35
  maxLength={maxLength}
35
36
  onChange={callAll(setCountChar, onChange)}
37
+ onPaste={onPaste}
36
38
  title={title}
37
39
  {...options}
38
40
  ref={useMergeRefs([options.ref, ref])}
@@ -12,5 +12,6 @@ export interface TextareaProps
12
12
  as?: React.ElementType;
13
13
  className?: string;
14
14
  title?: string;
15
+ onPaste?: React.ClipboardEventHandler<HTMLTextAreaElement>;
15
16
  setCountChar?: ReactEventHandler;
16
17
  }