Skip to content

Commit adfc848

Browse files
authored
Merge pull request #2403 from dxc-technology/PelayoFelgueroso/fileInput-fillParent
[minor] Add size prop to FileInput component
2 parents 97280df + 8b1300b commit adfc848

5 files changed

Lines changed: 72 additions & 9 deletions

File tree

apps/website/screens/components/file-input/code/FileInputCodePage.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ const sections = [
188188
<TableCode>false</TableCode>
189189
</td>
190190
</tr>
191+
<tr>
192+
<td>
193+
<DxcFlex direction="column" gap="var(--spacing-gap-xs)" alignItems="baseline">
194+
<StatusBadge status="new" />
195+
size
196+
</DxcFlex>
197+
</td>
198+
<td>
199+
<TableCode>'medium' | 'fillParent'</TableCode>
200+
</td>
201+
<td>Size of the component.</td>
202+
<td>
203+
<TableCode>'medium'</TableCode>
204+
</td>
205+
</tr>
191206
<tr>
192207
<td>tabIndex</td>
193208
<td>

packages/lib/src/file-input/FileInput.stories.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Meta, StoryObj } from "@storybook/react-vite";
22
import ExampleContainer from "../../.storybook/components/ExampleContainer";
33
import Title from "../../.storybook/components/Title";
44
import DxcFileInput from "./FileInput";
5+
import DxcContainer from "../container/Container";
56

67
export default {
78
title: "File Input",
@@ -510,6 +511,33 @@ const FileInput = () => (
510511
margin="xxlarge"
511512
/>
512513
</ExampleContainer>
514+
<Title title="Sizes" theme="light" level={3} />
515+
<ExampleContainer>
516+
<Title title="fillParent size" theme="light" level={4} />
517+
<DxcContainer width="200px">
518+
<DxcFileInput
519+
label="File input"
520+
helperText="Please select files"
521+
value={fileExample}
522+
callbackFile={() => {}}
523+
mode="filedrop"
524+
size="fillParent"
525+
/>
526+
</DxcContainer>
527+
</ExampleContainer>
528+
<ExampleContainer>
529+
<Title title="fillParent size" theme="light" level={4} />
530+
<DxcContainer width="200px">
531+
<DxcFileInput
532+
label="File input"
533+
helperText="Please select files"
534+
value={fileExample}
535+
callbackFile={() => {}}
536+
mode="dropzone"
537+
size="fillParent"
538+
/>
539+
</DxcContainer>
540+
</ExampleContainer>
513541
</>
514542
);
515543
// const EllipsisError = () => {

packages/lib/src/file-input/FileInput.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import { getFilePreview, isFileIncluded } from "./utils";
99
import HelperText from "../styles/forms/HelperText";
1010
import Label from "../styles/forms/Label";
1111

12-
const FileInputContainer = styled.div<{ margin: FileInputPropsType["margin"] }>`
12+
const FileInputContainer = styled.div<{
13+
margin: FileInputPropsType["margin"];
14+
mode: FileInputPropsType["mode"];
15+
size: FileInputPropsType["size"];
16+
}>`
1317
display: flex;
1418
flex-direction: column;
1519
margin: ${(props) => (props.margin && typeof props.margin !== "object" ? spaces[props.margin] : "0px")};
@@ -21,7 +25,7 @@ const FileInputContainer = styled.div<{ margin: FileInputPropsType["margin"] }>`
2125
props.margin && typeof props.margin === "object" && props.margin.bottom ? spaces[props.margin.bottom] : ""};
2226
margin-left: ${(props) =>
2327
props.margin && typeof props.margin === "object" && props.margin.left ? spaces[props.margin.left] : ""};
24-
width: fit-content;
28+
width: ${(props) => (props.mode !== "file" && props.size === "fillParent" ? "100%" : "fit-content")};
2529
`;
2630

2731
const FileContainer = styled.div<{ singleFileMode: boolean }>`
@@ -41,6 +45,7 @@ const FileItemListContainer = styled.div`
4145
display: flex;
4246
flex-direction: column;
4347
row-gap: var(--spacing-gap-xs);
48+
width: 100%;
4449
`;
4550

4651
const Container = styled.div`
@@ -54,6 +59,7 @@ const DragDropArea = styled.div<{
5459
mode: FileInputPropsType["mode"];
5560
disabled: FileInputPropsType["disabled"];
5661
isDragging: boolean;
62+
size: FileInputPropsType["size"];
5763
}>`
5864
box-sizing: border-box;
5965
display: flex;
@@ -62,7 +68,7 @@ const DragDropArea = styled.div<{
6268
? "flex-direction: row; column-gap: var(--spacing-gap-s);"
6369
: "justify-content: center; flex-direction: column; row-gap: var(--spacing-gap-s); height: 160px;"}
6470
align-items: center;
65-
width: 320px;
71+
width: ${(props) => (props.size === "fillParent" ? "100%" : "320px")};
6672
padding: ${(props) => (props.mode === "filedrop" ? `var(--spacing-padding-xxs)` : "var(--spacing-padding-m)")};
6773
overflow: hidden;
6874
border-radius: var(--border-radius-m);
@@ -116,6 +122,7 @@ const DxcFileInput = forwardRef<RefType, FileInputPropsType>(
116122
multiple = true,
117123
disabled = false,
118124
callbackFile,
125+
size = "medium",
119126
value,
120127
margin,
121128
tabIndex = 0,
@@ -230,7 +237,7 @@ const DxcFileInput = forwardRef<RefType, FileInputPropsType>(
230237
}, [value]);
231238

232239
return (
233-
<FileInputContainer margin={margin} ref={ref}>
240+
<FileInputContainer margin={margin} ref={ref} mode={mode} size={size}>
234241
{label && (
235242
<Label disabled={disabled} hasMargin={!helperText} htmlFor={fileInputId}>
236243
{label} {optional && <span>{translatedLabels.formFields.optionalLabel}</span>}
@@ -275,6 +282,7 @@ const DxcFileInput = forwardRef<RefType, FileInputPropsType>(
275282
onDelete={onDelete}
276283
tabIndex={tabIndex}
277284
key={`file-${index}`}
285+
size={size}
278286
/>
279287
))}
280288
</FileItemListContainer>
@@ -295,6 +303,7 @@ const DxcFileInput = forwardRef<RefType, FileInputPropsType>(
295303
<DragDropArea
296304
isDragging={isDragging}
297305
disabled={disabled}
306+
size={size}
298307
mode={mode}
299308
onDrop={handleDrop}
300309
onDragEnter={handleDragIn}
@@ -337,6 +346,7 @@ const DxcFileInput = forwardRef<RefType, FileInputPropsType>(
337346
onDelete={onDelete}
338347
tabIndex={tabIndex}
339348
key={`file-${index}`}
349+
size={size}
340350
/>
341351
))}
342352
</FileItemListContainer>

packages/lib/src/file-input/FileItem.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ const MainContainer = styled.div<{
1818
error: FileItemProps["error"];
1919
singleFileMode: FileItemProps["singleFileMode"];
2020
showPreview: FileItemProps["showPreview"];
21+
size: FileItemProps["size"];
2122
}>`
2223
box-sizing: border-box;
2324
display: flex;
2425
align-items: center;
2526
gap: var(--spacing-gap-m);
26-
width: ${(props) => (props.singleFileMode ? "230px" : "320px")};
27+
width: ${(props) => (props.size === "fillParent" ? "100%" : props.singleFileMode ? "230px" : "320px")};
2728
height: ${(props) => (props.singleFileMode || !props.showPreview) && "var(--height-m)"};
2829
padding: ${(props) =>
2930
props.showPreview && !props.singleFileMode
@@ -80,12 +81,15 @@ const FileName = styled.span`
8081
text-overflow: ellipsis;
8182
`;
8283

83-
const ErrorMessageContainer = styled.div<{ singleFileMode: FileItemProps["singleFileMode"] }>`
84+
const ErrorMessageContainer = styled.div<{
85+
singleFileMode: FileItemProps["singleFileMode"];
86+
size: FileItemProps["size"];
87+
}>`
8488
display: flex;
8589
align-items: center;
8690
gap: var(--spacing-gap-xs);
8791
color: var(--color-fg-error-medium);
88-
max-width: ${(props) => (props.singleFileMode ? "230px" : "320px")};
92+
max-width: ${(props) => (props.size === "fillParent" ? "100%" : props.singleFileMode ? "230px" : "320px")};
8993
`;
9094
const ErrorIcon = styled.span`
9195
display: flex;
@@ -114,6 +118,7 @@ const FileItem = ({
114118
type,
115119
onDelete,
116120
tabIndex,
121+
size = "medium",
117122
}: FileItemProps): JSX.Element => {
118123
const translatedLabels = useContext(HalstackLanguageContext);
119124
const [hasTooltip, setHasTooltip] = useState(false);
@@ -126,7 +131,7 @@ const FileItem = ({
126131

127132
return (
128133
<ListItem>
129-
<MainContainer error={error} singleFileMode={singleFileMode} showPreview={showPreview}>
134+
<MainContainer error={error} singleFileMode={singleFileMode} showPreview={showPreview} size={size}>
130135
{showPreview &&
131136
(type.includes("image") ? (
132137
<ImagePreview src={preview} alt={`Preview of ${fileName}`} />
@@ -150,7 +155,7 @@ const FileItem = ({
150155
</MainContainer>
151156
{error && (
152157
<TooltipWrapper condition={hasTooltip} label={error}>
153-
<ErrorMessageContainer role="alert" aria-live="assertive" singleFileMode={singleFileMode}>
158+
<ErrorMessageContainer role="alert" aria-live="assertive" singleFileMode={singleFileMode} size={size}>
154159
<ErrorIcon>
155160
<DxcIcon icon="filled_error" />
156161
</ErrorIcon>

packages/lib/src/file-input/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ type CommonProps = {
6868
* If true, if the file is an image, a preview of it will be shown. If not, an icon refering to the file type will be shown.
6969
*/
7070
showPreview?: boolean;
71+
/**
72+
* Size of the component.
73+
*/
74+
size?: "medium" | "fillParent";
7175
/**
7276
* Value of the tabindex attribute.
7377
*/
@@ -125,6 +129,7 @@ export type FileItemProps = {
125129
singleFileMode: boolean;
126130
tabIndex: number;
127131
type: string;
132+
size: "medium" | "fillParent";
128133
};
129134

130135
export default Props;

0 commit comments

Comments
 (0)