@beydesign/storybook 0.0.70 → 0.0.72

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,11 +1,70 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useRef, useState } from 'react';
3
3
  import { Box } from '@mui/material';
4
- import { FileDoc, FilePdf, FileTxt, UploadSimple } from '@phosphor-icons/react';
4
+ import { FileDoc, FilePdf, FileTxt, FileXls, FilePpt, FileJs, FileCss, FileHtml, FileImage, FileAudio, FileVideo, FileZip, FileCode, UploadSimple, FileCsv, } from '@phosphor-icons/react';
5
5
  import { Typography, TypographySize, TypographyWeight } from '../../Typography';
6
+ // Map file extensions to their corresponding icons
7
+ const fileIconMap = {
8
+ // Document/Text Files
9
+ '.doc': FileDoc,
10
+ '.docx': FileDoc,
11
+ '.txt': FileTxt,
12
+ '.rtf': FileDoc,
13
+ // Spreadsheet Files
14
+ '.csv': FileCsv,
15
+ '.xls': FileXls,
16
+ '.xlsx': FileXls,
17
+ // Presentation Files
18
+ '.ppt': FilePpt,
19
+ '.pptx': FilePpt,
20
+ // Code/Markup Files
21
+ '.js': FileJs,
22
+ '.ts': FileCode,
23
+ '.css': FileCss,
24
+ '.html': FileHtml,
25
+ '.json': FileJs,
26
+ '.xml': FileXls,
27
+ // Media Files
28
+ '.jpg': FileImage,
29
+ '.jpeg': FileImage,
30
+ '.png': FileImage,
31
+ '.gif': FileImage,
32
+ '.svg': FileImage,
33
+ '.mp3': FileAudio,
34
+ '.wav': FileAudio,
35
+ '.mp4': FileVideo,
36
+ '.mov': FileVideo,
37
+ // Archive Files
38
+ '.zip': FileZip,
39
+ '.rar': FileZip,
40
+ '.tar': FileZip,
41
+ '.gz': FileZip,
42
+ // PDF Files
43
+ '.pdf': FilePdf,
44
+ };
45
+ // Default icon for unknown file types
46
+ const defaultIcon = FileCode;
6
47
  export const FileUpload = ({ disabled, sx, acceptedFileTypes = '.pdf,.doc,.docx,.txt', maxFileSizeMB = 10, onFileSelect, }) => {
7
48
  const [isDragging, setIsDragging] = useState(false);
8
49
  const fileInputRef = useRef(null);
50
+ // Function to get the icons to display based on acceptedFileTypes
51
+ const getFileTypeIcons = () => {
52
+ // Parse the acceptedFileTypes string into an array of extensions
53
+ const extensions = acceptedFileTypes
54
+ .toLowerCase()
55
+ .split(',')
56
+ .map((ext) => ext.trim())
57
+ .filter((ext) => ext.startsWith('.'));
58
+ // Get unique icons for the accepted file types
59
+ const uniqueIcons = new Map();
60
+ extensions.forEach((ext) => {
61
+ const IconComponent = fileIconMap[ext] || defaultIcon;
62
+ // Use the component name as key to avoid duplicates
63
+ uniqueIcons.set(IconComponent.name, IconComponent);
64
+ });
65
+ return Array.from(uniqueIcons.values());
66
+ };
67
+ const fileIcons = getFileTypeIcons();
9
68
  const handleFileSelect = (files) => {
10
69
  if (!files || disabled)
11
70
  return;
@@ -65,5 +124,5 @@ export const FileUpload = ({ disabled, sx, acceptedFileTypes = '.pdf,.doc,.docx,
65
124
  ? 'var(--colors-light-text-text-disabled)'
66
125
  : 'var(--colors-light-text-text-accent)', style: { cursor: disabled ? 'not-allowed' : 'pointer' } }), _jsx(Typography, { text: 'or drag and drop', size: TypographySize.TextS, weight: TypographyWeight.Regular, color: disabled
67
126
  ? 'var(--colors-light-text-text-subtle)'
68
- : 'var(--colors-light-text-text-paragraph)' }), _jsxs(Box, { display: 'flex', flexDirection: 'row', gap: 'var(--spacing-tokens-size-in-px-spacing-spacing-xs)', children: [_jsx(FilePdf, { ...iconProps }), _jsx(FileDoc, { ...iconProps }), _jsx(FileTxt, { ...iconProps })] })] })] }));
127
+ : 'var(--colors-light-text-text-paragraph)' }), _jsxs(Box, { display: 'flex', flexDirection: 'row', gap: 'var(--spacing-tokens-size-in-px-spacing-spacing-xs)', children: [fileIcons.map((Icon, index) => (_jsx(Icon, { ...iconProps }, index))), fileIcons.length === 0 && _jsx(FileCode, { ...iconProps })] })] })] }));
69
128
  };
@@ -3,7 +3,7 @@ import { useState } from 'react';
3
3
  import { Box } from '@mui/material';
4
4
  import { Typography, TypographySize, TypographyWeight } from '../Typography';
5
5
  import { HintBubble, HintBubbleSize } from '../UI';
6
- export const TextArea = ({ label, value, onChange, placeholder, hintText, errorText, disabled, maxLength = 256, showMaxLengthIndicator = false, numberOfRows = 5, style, hintBubbleProps, hintBubbleText, required, labelTrailingElement, labelContainerStyle, }) => {
6
+ export const TextArea = ({ label, value, onChange, placeholder, hintText, errorText, disabled, allowMaxLength = false, maxLength = 256, showMaxLengthIndicator = false, numberOfRows = 5, style, hintBubbleProps, hintBubbleText, required, labelTrailingElement, labelContainerStyle, }) => {
7
7
  const [focused, setFocused] = useState(false);
8
8
  return (_jsx(Box, { display: 'flex', flexDirection: 'column', gap: 'var(--spacing-tokens-size-in-px-spacing-spacing-sm)', sx: style, children: _jsxs(Box, { display: 'flex', flexDirection: 'column', gap: 'var(--spacing-tokens-size-in-px-spacing-spacing-lg)', minWidth: '260px', children: [label && (_jsx(Typography, { text: label, size: TypographySize.HeadingXS, weight: TypographyWeight.SemiBold, required: required, trailingElement: labelTrailingElement, style: labelContainerStyle })), hintBubbleText && (_jsx(HintBubble, { text: hintBubbleText, size: HintBubbleSize.sm, ...hintBubbleProps })), _jsx(Box, { display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', bgcolor: 'var(--colors-light-background-bg-component)', border: `1px solid ${errorText
9
9
  ? 'var(--colors-light-border-border-error)'
@@ -19,5 +19,5 @@ export const TextArea = ({ label, value, onChange, placeholder, hintText, errorT
19
19
  : 'var(--colors-light-text-text-title)',
20
20
  backgroundColor: 'transparent',
21
21
  resize: 'none',
22
- }, maxLength: maxLength, onFocus: () => setFocused(true), onBlur: () => setFocused(false), required: required }) }), _jsxs(Box, { display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', children: [errorText ? (_jsx(Typography, { text: errorText, size: TypographySize.TextS, weight: TypographyWeight.Regular, color: 'var(--colors-light-text-text-error)' })) : hintText ? (_jsx(Typography, { text: hintText, size: TypographySize.TextS, weight: TypographyWeight.Regular, color: 'var(--colors-light-text-text-subtle)' })) : (_jsx(Box, { style: { flex: 1 } })), showMaxLengthIndicator && maxLength && (_jsx(Typography, { text: `${maxLength - value.length}`, size: TypographySize.TextS, weight: TypographyWeight.Regular, color: 'var(--colors-light-text-text-subtle)', style: { alignSelf: 'flex-end' } }))] })] }) }));
22
+ }, maxLength: allowMaxLength ? maxLength : undefined, onFocus: () => setFocused(true), onBlur: () => setFocused(false), required: required }) }), _jsxs(Box, { display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', children: [errorText ? (_jsx(Typography, { text: errorText, size: TypographySize.TextS, weight: TypographyWeight.Regular, color: 'var(--colors-light-text-text-error)' })) : hintText ? (_jsx(Typography, { text: hintText, size: TypographySize.TextS, weight: TypographyWeight.Regular, color: 'var(--colors-light-text-text-subtle)' })) : (_jsx(Box, { style: { flex: 1 } })), showMaxLengthIndicator && allowMaxLength && maxLength && (_jsx(Typography, { text: `${maxLength - value.length}`, size: TypographySize.TextS, weight: TypographyWeight.Regular, color: 'var(--colors-light-text-text-subtle)', style: { alignSelf: 'flex-end' } }))] })] }) }));
23
23
  };
@@ -141,8 +141,21 @@ declare const meta: {
141
141
  };
142
142
  };
143
143
  };
144
+ allowMaxLength: {
145
+ control: "boolean";
146
+ description: string;
147
+ table: {
148
+ type: {
149
+ summary: string;
150
+ };
151
+ defaultValue: {
152
+ summary: string;
153
+ };
154
+ };
155
+ };
144
156
  };
145
157
  };
146
158
  export default meta;
147
159
  type Story = StoryObj<typeof meta>;
148
160
  export declare const Default: Story;
161
+ export declare const WithMaxLength: Story;
@@ -111,6 +111,14 @@ const meta = {
111
111
  type: { summary: 'ReactNode' },
112
112
  },
113
113
  },
114
+ allowMaxLength: {
115
+ control: 'boolean',
116
+ description: 'Whether to apply max length restriction',
117
+ table: {
118
+ type: { summary: 'boolean' },
119
+ defaultValue: { summary: 'false' },
120
+ },
121
+ },
114
122
  },
115
123
  };
116
124
  export default meta;
@@ -118,6 +126,17 @@ export const Default = {
118
126
  args: {
119
127
  label: "Agent's name",
120
128
  value: 'Anna',
121
- onChange: () => { },
129
+ onChange: (_value) => { },
130
+ },
131
+ };
132
+ export const WithMaxLength = {
133
+ args: {
134
+ label: 'Limited Text Area',
135
+ value: '',
136
+ onChange: (_value) => { },
137
+ allowMaxLength: true,
138
+ maxLength: 100,
139
+ showMaxLengthIndicator: true,
140
+ placeholder: 'Enter text (max 100 characters)',
122
141
  },
123
142
  };
@@ -19,6 +19,8 @@ export type TextAreaProps = {
19
19
  errorText?: string;
20
20
  /** Text input disabled */
21
21
  disabled?: boolean;
22
+ /** Whether to apply max length restriction */
23
+ allowMaxLength?: boolean;
22
24
  /** Text input max length */
23
25
  maxLength?: number;
24
26
  /** Text input show max length indicator */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@beydesign/storybook",
3
3
  "private": false,
4
- "version": "0.0.70",
4
+ "version": "0.0.72",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",