Skip to content
Merged
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
58 changes: 58 additions & 0 deletions packages/@react-spectrum/listbox/docs/ListBox.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!-- Copyright 2020 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/listbox';
import {HeaderInfo, PropTable} from '@react-spectrum/docs';
import packageData from '../package.json';

```jsx import
import {ListBox, Section, Item} from '@react-spectrum/listbox';
```

# ListBox

<p>{docs.exports.ListBox.description}</p>

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

## Example

```tsx example
<ListBox width={200} aria-label="label">
<Section title="Justify">
<Item>Left</Item>
<Item>Middle</Item>
<Item>Right</Item>
</Section>
<Section title="Align">
<Item>Top</Item>
<Item>Center</Item>
<Item>Bottom</Item>
</Section>
</ListBox>
```

## Content

### Accessibility

### Internationalization

## Events

## Props

<PropTable component={docs.exports.ListBox} links={docs.links} />

## Visual Options
5 changes: 5 additions & 0 deletions packages/@react-spectrum/listbox/src/ListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ function ListBox<T>(props: SpectrumListBoxProps<T>, ref: DOMRef<HTMLDivElement>)

// forwardRef doesn't support generic parameters, so cast the result to the correct type
// https://stackoverflow.com/questions/58469229/react-with-typescript-generics-while-using-react-forwardref


/**
* Listbox shows lists
Copy link
Member

Choose a reason for hiding this comment

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

😆

*/
const _ListBox = React.forwardRef(ListBox) as <T>(props: SpectrumListBoxProps<T> & {ref?: DOMRef<HTMLDivElement>}) => ReactElement;
export {_ListBox as ListBox};
2 changes: 1 addition & 1 deletion packages/@react-types/shared/src/collections.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export interface KeyboardDelegate {

/** Returns the key visually one page above the given one, or `null` for none. */
getKeyPageAbove?(key: Key): Key,

/** Returns the first key, or `null` for none. */
getFirstKey?(): Key,

Expand Down
9 changes: 7 additions & 2 deletions packages/dev/docs/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function Type({type}) {
case 'alias':
return <code className={typographyStyles['spectrum-Code4']}><Type type={type.value} /></code>;
default:
console.log('UNKNOWN TYPE', type);
console.log('no render component for TYPE', type);
return null;
}
}
Expand Down Expand Up @@ -124,7 +124,12 @@ function JoinList({elements, joiner}) {
return elements
.reduce((acc, v, i) => [
...acc,
<span className="token punctuation" key={`join${v.name || v.raw}${i}`} style={{whiteSpace: 'pre-wrap'}}>{joiner}</span>,
<span
className="token punctuation"
key={`join${v.name || v.raw}${i}`}
style={{whiteSpace: 'pre-wrap'}}>
{joiner}
</span>,
<Type type={v} key={`type${v.name || v.raw}${i}`} />
], []).slice(1);
}
Expand Down
17 changes: 14 additions & 3 deletions packages/dev/parcel-packager-docs/DocsPackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

const {Packager} = require('@parcel/plugin');
const v8 = require('v8');

module.exports = new Packager({
async package({bundle, bundleGraph, options}) {
Expand Down Expand Up @@ -171,21 +172,31 @@ module.exports = new Packager({
});

async function parse(asset) {
let code = await asset.getCode();
return [asset.id, JSON.parse(code)];
let buffer = await asset.getBuffer();
return [asset.id, v8.deserialize(buffer)];
}

let cache = new Map();
// cache things in pre-visit order so the references exist
function walk(obj, fn, k = null) {
let recurse = (obj) => {
if (cache.has(obj)) {
return cache.get(obj);
}
if (Array.isArray(obj)) {
return obj.map((item, i) => walk(item, fn, k));
let resultArray = [];
cache.set(obj, resultArray);
obj.forEach((item, i) => resultArray[i] = walk(item, fn, k));
return resultArray;
} else if (obj && typeof obj === 'object') {
let res = {};
cache.set(obj, res);
for (let key in obj) {
res[key] = walk(obj[key], fn, key);
}
return res;
} else {
cache.set(obj, obj);
return obj;
}
};
Expand Down
Loading