Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions src/big-picture/src/components/common/file-explorer-modal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import "./styles.scss";

import {
CheckCircleIcon,
FolderIcon,
FolderOpenIcon,
} from "@phosphor-icons/react";
import { Modal } from "../modal";
import { VerticalFocusGroup } from "../vertical-focus-group";
import { FocusItem } from "../focus-item";
import { EmptyState } from "../empty-state";
import { Skeleton } from "../skeleton";
import { getEntryIcon } from "../../../helpers";
import { getEntryMeta } from "./utils";
import {
useFileExplorer,
type FileExplorerModalProps,
} from "./use-file-explorer";

export { type FileExplorerModalProps } from "./use-file-explorer";
export { type FileFilter } from "./utils";

export function FileExplorerModal(props: Readonly<FileExplorerModalProps>) {
const vm = useFileExplorer(props);

return (
<Modal
visible={props.visible}
onClose={props.onClose}
onBack={vm.hasParent ? vm.goToParent : undefined}
title={props.title}
closeOnB={false}
closeOnEscape={false}
className="file-explorer-modal"
>
<div className="file-explorer">
{vm.isLoading && (
<div className="file-explorer__list">
<div className="file-explorer__skeleton-group">
{Array.from({ length: vm.SKELETON_COUNT }, (_, i) => (
<Skeleton key={i} className="file-explorer__skeleton" />
))}
</div>
</div>
)}

{vm.error && (
<div className="file-explorer__list">
<div className="file-explorer__status file-explorer__status--error">
{vm.error}
</div>
</div>
)}

{!vm.isLoading && !vm.error && (
<VerticalFocusGroup
regionId={vm.fileListRegionId}
className="file-explorer__list"
>
<div className="file-explorer__path-input-wrapper">
<FocusItem
stealFocusOnAppear
actions={{ primary: () => vm.pathInputRef.current?.focus() }}
>
<input
ref={vm.pathInputRef}
className="file-explorer__path-input"
type="text"
placeholder={vm.currentPath || vm.PATH_INPUT_PLACEHOLDER}
value={vm.pathInputValue}
onChange={(e) => vm.setPathInputValue(e.target.value)}
onKeyDown={vm.handlePathInputKeyDown}
/>
</FocusItem>

<FolderOpenIcon
size={24}
weight="fill"
className="file-explorer__path-input-icon"
/>
</div>

{vm.showSelectThisDir && (
<FocusItem
id="file-explorer-select-dir"
actions={{ primary: vm.handleSelectThisDirectory }}
asChild
>
<button
className="file-explorer__item file-explorer__item--select-dir"
onClick={vm.handleSelectThisDirectory}
>
<span className="file-explorer__item-icon">
<CheckCircleIcon size={22} weight="fill" />
</span>

<span>Select this directory</span>
</button>
</FocusItem>
)}

{vm.showDriveList && (
<>
<div className="file-explorer__section-label">
{vm.DRIVES_LABEL}
</div>

{vm.drives.map((drive) => (
<FocusItem
key={drive}
actions={{ primary: () => vm.navigateToDrive(drive) }}
asChild
>
<button
className="file-explorer__item"
onClick={() => vm.navigateToDrive(drive)}
>
<FolderIcon size={22} weight="fill" />
<span>{drive}</span>
</button>
</FocusItem>
))}
</>
)}

{vm.filteredEntries.length === 0 &&
!vm.showDriveList &&
!vm.isLoading && (
<EmptyState
className="file-explorer__empty"
icon={<FolderOpenIcon size={32} weight="fill" />}
title={vm.emptyTitle}
/>
)}

{vm.filteredEntries.map((entry) => (
<FocusItem
key={entry.path}
actions={{ primary: () => vm.handleEntrySelect(entry) }}
asChild
>
<button
className="file-explorer__item"
onClick={() => vm.handleEntrySelect(entry)}
>
<span className="file-explorer__item-icon">
{getEntryIcon(entry)}
</span>
<span className="file-explorer__item-name">{entry.name}</span>
<span className="file-explorer__item-meta">
{getEntryMeta(entry)}
</span>
</button>
</FocusItem>
))}
</VerticalFocusGroup>
)}
</div>
</Modal>
);
}
165 changes: 165 additions & 0 deletions src/big-picture/src/components/common/file-explorer-modal/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
.file-explorer-modal {
max-height: min(100%, calc(100vh - 4rem), 60vh);
}

.file-explorer {
display: flex;
flex-direction: column;
gap: calc(var(--spacing-unit) * 2);
min-height: 0;
flex: 1;

&__path-input-wrapper {
position: relative;
display: flex;
align-items: center;
width: 100%;

> [data-focus-wrapper] {
width: 100%;
}
}

&__path-input {
width: 100%;
height: 44px;
padding: calc(var(--spacing-unit) * 2) calc(var(--spacing-unit) * 4);
padding-left: 46px;
border-radius: calc(var(--spacing-unit) * 2);
font-family: var(--font-space-grotesk);
font-size: 14px;
line-height: 16.59px;
border: 1px solid var(--secondary-border);
background-color: var(--background);
color: var(--text);
transition: border-color 0.2s ease-in-out;

&:hover {
border-color: var(--secondary-hover);
}

&:focus-visible,
[data-focus-visible="true"] & {
outline: none;
border-color: rgba(255, 255, 255, 0.6);
}

&::placeholder {
color: var(--text-secondary);
}
}

&__path-input-icon {
position: absolute;
display: flex;
align-items: center;
justify-content: center;
left: 10px;
color: var(--text-secondary);
pointer-events: none;
}

&__list {
flex: 1;
min-height: 0;
overflow-y: auto;
}

&__skeleton-group {
display: flex;
flex-direction: column;
gap: calc(var(--spacing-unit) * 2);
padding: calc(var(--spacing-unit) * 2) 0;
}

&__skeleton {
height: 36px;
border-radius: calc(var(--spacing-unit) * 1.5);
}

&__status {
display: flex;
align-items: center;
justify-content: center;
padding: calc(var(--spacing-unit) * 8);
color: var(--text-secondary);
font-size: 0.875rem;

&--error {
color: var(--text-error);
}
}

&__section-label {
font-size: 0.75rem;
color: var(--text-secondary);
padding: calc(var(--spacing-unit) * 2) calc(var(--spacing-unit) * 3);
text-transform: uppercase;
letter-spacing: 0.05em;
}

&__item {
display: flex;
align-items: center;
gap: calc(var(--spacing-unit) * 2);
padding: calc(var(--spacing-unit) * 2) calc(var(--spacing-unit) * 3);
border-radius: calc(var(--spacing-unit) * 1.5);
cursor: pointer;
transition: background-color 0.15s ease;
color: var(--text);
font-size: 0.875rem;
width: 100%;
text-align: left;
border: none;
font-family: var(--font-space-grotesk), sans-serif;
background: transparent;

&:hover {
background-color: var(--secondary-hover);
}

&[data-focus-visible="true"] {
background-color: var(--secondary-hover);
outline: none;
}

&--select-dir {
&:hover,
&[data-focus-visible="true"] {
background-color: var(--secondary-hover);
}
}
}

&__item-icon {
display: flex;
align-items: center;
flex-shrink: 0;
opacity: 0.7;
}

&__item-name {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

&__item-meta {
margin-left: auto;
font-size: 0.75rem;
color: var(--text-secondary);
opacity: 0;
transition: opacity 0.15s ease;
white-space: nowrap;
flex-shrink: 0;
}

&__item:hover &__item-meta,
&__item[data-focus-visible="true"] &__item-meta {
opacity: 0.6;
}

&__empty {
padding: calc(var(--spacing-unit) * 4) 0 calc(var(--spacing-unit) * 16) 0;
}
}
Loading
Loading