Skip to content

Commit

Permalink
Re-export FileTrigger package in RSP (#6295)
Browse files Browse the repository at this point in the history
* re-export filetrigger to rsp

* fix lint

* add filetrigger docs to rsp

* fix typecheck docs

* update copyright year

* update to be closer to rsp docs template

---------

Co-authored-by: Danni <darobins@adobe.com>
  • Loading branch information
yihuiliao and dannify committed May 1, 2024
1 parent 1bd538f commit 0e05b7e
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/@adobe/react-spectrum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@react-spectrum/dialog": "^3.8.9",
"@react-spectrum/divider": "^3.5.11",
"@react-spectrum/dnd": "^3.3.8",
"@react-spectrum/filetrigger": "^3.0.0",
"@react-spectrum/form": "^3.7.4",
"@react-spectrum/icon": "^3.7.11",
"@react-spectrum/illustratedmessage": "^3.4.11",
Expand Down
2 changes: 2 additions & 0 deletions packages/@adobe/react-spectrum/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export {ContextualHelp} from '@react-spectrum/contextualhelp';
export {AlertDialog, Dialog, DialogTrigger, DialogContainer, useDialogContainer} from '@react-spectrum/dialog';
export {DateField, DatePicker, DateRangePicker, TimeField} from '@react-spectrum/datepicker';
export {Divider} from '@react-spectrum/divider';
export {FileTrigger} from '@react-spectrum/filetrigger';
export {Form} from '@react-spectrum/form';
export {Icon} from '@react-spectrum/icon';
export {IllustratedMessage} from '@react-spectrum/illustratedmessage';
Expand Down Expand Up @@ -81,6 +82,7 @@ export type {SpectrumContextualHelpProps} from '@react-spectrum/contextualhelp';
export type {DialogContainerValue, SpectrumAlertDialogProps, SpectrumDialogContainerProps, SpectrumDialogProps, SpectrumDialogTriggerProps} from '@react-spectrum/dialog';
export type {SpectrumDateFieldProps, SpectrumDatePickerProps, SpectrumDateRangePickerProps, SpectrumTimeFieldProps} from '@react-spectrum/datepicker';
export type {SpectrumDividerProps} from '@react-spectrum/divider';
export type {FileTriggerProps} from '@react-spectrum/filetrigger';
export type {SpectrumFormProps} from '@react-spectrum/form';
export type {IconProps, IllustrationProps} from '@react-spectrum/icon';
export type {SpectrumIllustratedMessageProps} from '@react-spectrum/illustratedmessage';
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-spectrum/dropzone/docs/DropZone.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function Draggable() {
A DropZone accepts an [IllustratedMessage](IllustratedMessage.html) as a child which is comprised of three areas: an illustration, a title, and a body. Each of these sections can be populated by providing the following components to the IllustratedMessage as children: a SVG, a [Heading](Heading.html) (title), and a [Content](Content.html) (body). A [FileTrigger](../react-aria/FileTrigger.html) is commonly paired with a DropZone to allow a user to choose files from their device.

```tsx example
import {FileTrigger} from 'react-aria-components';
import {FileTrigger} from '@adobe/react-spectrum';

function Example() {
let [isFilled, setIsFilled] = React.useState(false);
Expand Down Expand Up @@ -343,7 +343,7 @@ A DropZone displays visual feedback to the user when a drag hovers over the drop
In the below example, the drop zone only supports dropping JPEG images. If a JPEG is dragged over the drop zone, it will be highlighted and the operating system will display a copy cursor. If another type is dragged over the drop zone, then there is no visual feedback, indicating that a drop is not accepted.

```tsx example
import {FileTrigger} from 'react-aria-components';
import {FileTrigger} from '@adobe/react-spectrum';

function Example() {
let [filledSrc, setFilledSrc] = React.useState(null);
Expand Down
3 changes: 3 additions & 0 deletions packages/@react-spectrum/filetrigger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @react-spectrum/filetrigger

This package is part of [react-spectrum](https://github.com/adobe/react-spectrum). See the repo for more details.
142 changes: 142 additions & 0 deletions packages/@react-spectrum/filetrigger/docs/FileTrigger.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{/* Copyright 2024 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License. */}

import {Layout} from '@react-spectrum/docs';
export default Layout;

import docs from 'docs:@react-spectrum/filetrigger';
import typesDocs from 'docs:@react-types/shared/src/events.d.ts';
import {PropTable, HeaderInfo, TypeLink, PageDescription, StateTable} from '@react-spectrum/docs';
import styles from '@react-spectrum/docs/src/docs.css';
import packageData from '@react-spectrum/filetrigger/package.json';
import ChevronRight from '@spectrum-icons/workflow/ChevronRight';
import {Divider} from '@react-spectrum/divider';
import {ExampleCard} from '@react-spectrum/docs/src/ExampleCard';
import {Keyboard} from '@react-spectrum/text';
import Button from '@react-spectrum/docs/pages/assets/component-illustrations/ActionButton.svg';
import Link from '@react-spectrum/docs/pages/assets/component-illustrations/Link.svg';

---
category: Buttons
---

# FileTrigger

<PageDescription>{docs.exports.FileTrigger.description}</PageDescription>

<HeaderInfo
packageData={packageData}
componentNames={['FileTrigger']} />

## Example

```tsx example
import {FileTrigger, Button} from '@adobe/react-spectrum';

function Example(){
let [file, setFile] = React.useState(null);

return (
<>
<FileTrigger
onSelect={(e) => {
let files = Array.from(e);
let filenames = files.map((file) => file.name);
setFile(filenames);
}}>
<Button variant="accent">Select a file</Button>
</FileTrigger>
{file && file}
</>
)
}
```

## Content

A `FileTrigger` wraps around a pressable child such as a button, and includes a visually hidden input element that allows the user to select files from their device.

```tsx
import {FileTrigger, Button} from '@adobe/react-spectrum';

<FileTrigger>
<Button />
</FileTrigger>
```

If a visual label is not provided on the pressable child, then an `aria-label` or `aria-labelledby` prop must be passed to identify the file trigger to assistive technology.

## Accepted file types

By default, the file trigger will accept any file type. To support only certain file types, pass an array of the [mime type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types) of files via the `acceptedFileTypes` prop.

```tsx example
<FileTrigger acceptedFileTypes={['image/png']}>
<Button variant="primary">Select files</Button>
</FileTrigger>
```

## Multiple files

A file trigger can accept multiple files by passsing the `allowsMultiple` property.

```tsx example
<FileTrigger allowsMultiple>
<Button variant="primary">Upload your files</Button>
</FileTrigger>
```

## Directory selection

To enable selecting directories instead of files, use the `acceptDirectory` property.

This reflects the [webkitdirectory](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory) HTML attribute and allows users to select directories and their contents. Please note that support for this feature varies from browser to browser.


```tsx example
function Example () {
let [files, setFiles] = React.useState([]);

return (
<>
<FileTrigger
acceptDirectory
onSelect={(e) => {
if (e) {
let fileList = [...e].map(file => file.webkitRelativePath !== "" ? file.webkitRelativePath : file.name);
setFiles(fileList);
}
}} >
<Button variant="accent">Upload</Button>
</FileTrigger>
{files && <ul>
{files.map((file, index) => (
<li key={index}>{file}</li>
))}
</ul>}
</>
);
}
```

## Media capture

To specify the media capture mechanism to capture media on the spot, pass `user` for the user-facing camera or `environment` for the outward-facing camera via the `defaultCamera` prop.

This behavior only works on mobile devices. On desktop devices, it will open the file system like normal. [Read more about capture](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture).

```tsx example
<FileTrigger defaultCamera="environment">
<Button variant="accent">Open Camera</Button>
</FileTrigger>
````

## Props

<PropTable component={docs.exports.FileTrigger} links={docs.links} />
12 changes: 12 additions & 0 deletions packages/@react-spectrum/filetrigger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
export * from './src';
49 changes: 49 additions & 0 deletions packages/@react-spectrum/filetrigger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@react-spectrum/filetrigger",
"version": "3.0.0",
"description": "Spectrum UI components in React",
"license": "Apache-2.0",
"main": "dist/main.js",
"module": "dist/module.js",
"exports": {
"types": "./dist/types.d.ts",
"import": "./dist/import.mjs",
"require": "./dist/main.js"
},
"types": "dist/types.d.ts",
"source": "src/index.ts",
"files": [
"dist",
"src"
],
"sideEffects": [
"*.css"
],
"targets": {
"main": {
"includeNodeModules": [
"@adobe/spectrum-css-temp"
]
},
"module": {
"includeNodeModules": [
"@adobe/spectrum-css-temp"
]
}
},
"repository": {
"type": "git",
"url": "https://github.com/adobe/react-spectrum"
},
"dependencies": {
"react-aria-components": "^1.1.1",
"@swc/helpers": "^0.5.0"
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0",
"@react-spectrum/provider": "^3.0.0"
},
"publishConfig": {
"access": "public"
}
}
16 changes: 16 additions & 0 deletions packages/@react-spectrum/filetrigger/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/// <reference types="css-module-types" />

export {FileTrigger} from 'react-aria-components';
export type {FileTriggerProps} from 'react-aria-components';
8 changes: 8 additions & 0 deletions packages/dev/docs/pages/react-spectrum/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import LabeledValue from '../assets/component-illustrations/LabeledValue.svg';
import Badge from '../assets/component-illustrations/Badge.svg';
import TagGroup from '../assets/component-illustrations/TagGroup.svg';
import DropZone from '../assets/component-illustrations/DropZone.svg';
import FileTrigger from '../assets/component-illustrations/FileTrigger.svg'

---
category: Libraries
Expand Down Expand Up @@ -155,6 +156,13 @@ A React implementation of Spectrum, Adobe’s design system.
<ActionGroup />
</ExampleCard>

<ExampleCard
url="FileTrigger.html"
title="FileTrigger"
description="A file trigger allows a user to access the file system with a Button.">
<FileTrigger />
</ExampleCard>

</section>

### Pickers
Expand Down

1 comment on commit 0e05b7e

@rspbot
Copy link

@rspbot rspbot commented on 0e05b7e May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.