Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListView updates #2238

Merged
merged 20 commits into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 2 additions & 1 deletion packages/@react-spectrum/actiongroup/src/ActionGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {ActionButton} from '@react-spectrum/button';
import {AriaLabelingProps, DOMProps, DOMRef, Node, StyleProps} from '@react-types/shared';
import buttonStyles from '@adobe/spectrum-css-temp/components/button/vars.css';
import ChevronDownMedium from '@spectrum-icons/ui/ChevronDownMedium';
import {classNames, SlotProvider, useDOMRef, useStyleProps, useValueEffect} from '@react-spectrum/utils';
import {classNames, SlotProvider, useDOMRef, useSlotProps, useStyleProps, useValueEffect} from '@react-spectrum/utils';
import {filterDOMProps, mergeProps, useId, useLayoutEffect, useResizeObserver} from '@react-aria/utils';
import {Item, Menu, MenuTrigger} from '@react-spectrum/menu';
import {ListState, useListState} from '@react-stately/list';
Expand All @@ -32,6 +32,7 @@ import {useProviderProps} from '@react-spectrum/provider';

function ActionGroup<T extends object>(props: SpectrumActionGroupProps<T>, ref: DOMRef<HTMLDivElement>) {
props = useProviderProps(props);
props = useSlotProps(props, 'actionGroup');

let {
isEmphasized,
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-spectrum/button/src/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* governing permissions and limitations under the License.
*/

import {classNames, SlotProvider, useFocusableRef, useStyleProps} from '@react-spectrum/utils';
import {classNames, SlotProvider, useFocusableRef, useSlotProps, useStyleProps} from '@react-spectrum/utils';
import {FocusableRef} from '@react-types/shared';
import {FocusRing} from '@react-aria/focus';
import {mergeProps} from '@react-aria/utils';
Expand All @@ -24,6 +24,7 @@ import {useProviderProps} from '@react-spectrum/provider';

function ActionButton(props: SpectrumActionButtonProps, ref: FocusableRef<HTMLButtonElement>) {
props = useProviderProps(props);
props = useSlotProps(props, 'actionButton');
let {
isQuiet,
isDisabled,
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-spectrum/link/src/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* governing permissions and limitations under the License.
*/

import {classNames, getWrappedElement, useStyleProps} from '@react-spectrum/utils';
import {classNames, getWrappedElement, useSlotProps, useStyleProps} from '@react-spectrum/utils';
import {FocusRing} from '@react-aria/focus';
import {mergeProps} from '@react-aria/utils';
import React, {useRef} from 'react';
Expand All @@ -26,6 +26,7 @@ import {useProviderProps} from '@react-spectrum/provider';
*/
export function Link(props: SpectrumLinkProps) {
props = useProviderProps(props);
props = useSlotProps(props, 'link');
let {
variant = 'primary',
isQuiet,
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/ar-AE.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "جار التحميل...",
"loadingMore": "جار تحميل المزيد..."
"loadingMore": "جار تحميل المزيد...",
"select": "يحدد"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/bg-BG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Зареждане...",
"loadingMore": "Зареждане на още..."
"loadingMore": "Зареждане на още...",
"select": "Избирам"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/cs-CZ.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Načítání...",
"loadingMore": "Načítání dalších..."
"loadingMore": "Načítání dalších...",
"select": "Vybrat"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/da-DK.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Indlæser ...",
"loadingMore": "Indlæser flere ..."
"loadingMore": "Indlæser flere ...",
"select": "Vælg"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/de-DE.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Laden...",
"loadingMore": "Mehr laden ..."
"loadingMore": "Mehr laden ...",
"select": "Auswählen"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/el-GR.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Φόρτωση...",
"loadingMore": "Φόρτωση περισσότερων..."
"loadingMore": "Φόρτωση περισσότερων...",
"select": "Επιλέγω"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/en-US.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Loading…",
"loadingMore": "Loading more…"
"loadingMore": "Loading more…",
"select": "Select"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/es-ES.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Cargando…",
"loadingMore": "Cargando más…"
"loadingMore": "Cargando más…",
"select": "Seleccionar"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/et-EE.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Laadimine...",
"loadingMore": "Laadi rohkem..."
"loadingMore": "Laadi rohkem...",
"select": "Vali"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/fi-FI.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Ladataan…",
"loadingMore": "Ladataan lisää…"
"loadingMore": "Ladataan lisää…",
"select": "Valitse"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/fr-FR.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Chargement...",
"loadingMore": "Chargement supplémentaire..."
"loadingMore": "Chargement supplémentaire...",
"select": "Sélectionner"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/he-IL.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "טוען...",
"loadingMore": "טוען עוד..."
"loadingMore": "טוען עוד...",
"select": "בחר"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/hr-HR.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Učitavam...",
"loadingMore": "Učitavam još..."
"loadingMore": "Učitavam još...",
"select": "Odaberi"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/hu-HU.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Betöltés folyamatban…",
"loadingMore": "Továbbiak betöltése folyamatban…"
"loadingMore": "Továbbiak betöltése folyamatban…",
"select": "Kijelölés"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/it-IT.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Caricamento...",
"loadingMore": "Caricamento altri..."
"loadingMore": "Caricamento altri...",
"select": "Seleziona"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/ja-JP.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "読み込み中...",
"loadingMore": "さらに読み込み中..."
"loadingMore": "さらに読み込み中...",
"select": "選択"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/ko-KR.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "로드 중",
"loadingMore": "추가 로드 중"
"loadingMore": "추가 로드 중",
"select": "선택"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/lt-LT.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Įkeliama...",
"loadingMore": "Įkeliama daugiau..."
"loadingMore": "Įkeliama daugiau...",
"select": "Žymėti"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/lv-LV.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Notiek ielāde...",
"loadingMore": "Tiek ielādēts vēl..."
"loadingMore": "Tiek ielādēts vēl...",
"select": "Atlasīt"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/nb-NO.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Laster inn ...",
"loadingMore": "Laster inn flere ..."
"loadingMore": "Laster inn flere ...",
"select": "Velg"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/nl-NL.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Laden...",
"loadingMore": "Meer laden..."
"loadingMore": "Meer laden...",
"select": "Selecteren"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/pl-PL.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Ładowanie...",
"loadingMore": "Wczytywanie większej liczby..."
"loadingMore": "Wczytywanie większej liczby...",
"select": "Zaznacz"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/pt-BR.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Carregando...",
"loadingMore": "Carregando mais..."
"loadingMore": "Carregando mais...",
"select": "Selecionar"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/pt-PT.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "A carregar...",
"loadingMore": "A carregar mais..."
"loadingMore": "A carregar mais...",
"select": "Selecionar"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/ro-RO.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Se încarcă...",
"loadingMore": "Se încarcă mai multe..."
"loadingMore": "Se încarcă mai multe...",
"select": "Selectați"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/ru-RU.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Загрузка...",
"loadingMore": "Дополнительная загрузка..."
"loadingMore": "Дополнительная загрузка...",
"select": "Выбрать"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/sk-SK.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Načítava sa...",
"loadingMore": "Načítava sa viac..."
"loadingMore": "Načítava sa viac...",
"select": "Vybrať"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/sl-SI.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Nalaganje...",
"loadingMore": "Nalaganje več vsebine..."
"loadingMore": "Nalaganje več vsebine...",
"select": "Izberi"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/sr-SP.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Učitavam...",
"loadingMore": "Učitavam još..."
"loadingMore": "Učitavam još...",
"select": "Izaberi"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/sv-SE.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Läser in...",
"loadingMore": "Läser in mer..."
"loadingMore": "Läser in mer...",
"select": "Markera"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/tr-TR.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Yükleniyor...",
"loadingMore": "Daha fazla yükleniyor..."
"loadingMore": "Daha fazla yükleniyor...",
"select": "Seç"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/uk-UA.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "Завантаження…",
"loadingMore": "Завантаження інших об’єктів..."
"loadingMore": "Завантаження інших об’єктів...",
"select": "Вибрати"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/zh-CN.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "正在加载...",
"loadingMore": "正在加载更多..."
"loadingMore": "正在加载更多...",
"select": "选择"
}
3 changes: 2 additions & 1 deletion packages/@react-spectrum/list/intl/zh-TW.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"loading": "正在載入",
"loadingMore": "正在載入更多…"
"loadingMore": "正在載入更多…",
"select": "選取"
}
1 change: 1 addition & 0 deletions packages/@react-spectrum/list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@react-aria/utils": "^3.8.2",
"@react-aria/virtualizer": "^3.3.4",
"@react-spectrum/button": "^3.5.1",
"@react-spectrum/checkbox": "^3.2.3",
"@react-spectrum/layout": "^3.2.1",
"@react-spectrum/listbox": "^3.5.1",
"@react-spectrum/progress": "^3.1.3",
Expand Down
24 changes: 17 additions & 7 deletions packages/@react-spectrum/list/src/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import {AriaLabelingProps, CollectionBase, DOMProps, DOMRef, StyleProps} from '@react-types/shared';
import {AriaLabelingProps, CollectionBase, DOMProps, DOMRef, MultipleSelection, StyleProps} from '@react-types/shared';
import {classNames, useDOMRef, useStyleProps} from '@react-spectrum/utils';
import {GridCollection, useGridState} from '@react-stately/grid';
import {GridKeyboardDelegate, useGrid} from '@react-aria/grid';
Expand All @@ -20,7 +20,7 @@ import {ListState, useListState} from '@react-stately/list';
import listStyles from './listview.css';
import {ListViewItem} from './ListViewItem';
import {ProgressCircle} from '@react-spectrum/progress';
import React, {ReactElement, useContext, useMemo} from 'react';
import React, {Key, ReactElement, useContext, useMemo, useState} from 'react';
import {useCollator, useLocale, useMessageFormatter} from '@react-aria/i18n';
import {useProvider} from '@react-spectrum/provider';
import {Virtualizer} from '@react-aria/virtualizer';
Expand All @@ -33,7 +33,7 @@ export function useListLayout<T>(state: ListState<T>) {
let collator = useCollator({usage: 'search', sensitivity: 'base'});
let layout = useMemo(() =>
new ListLayout<T>({
estimatedRowHeight: scale === 'large' ? 48 : 32,
estimatedRowHeight: scale === 'large' ? 40 : 32,
padding: 0,
collator
})
Expand All @@ -44,19 +44,28 @@ export function useListLayout<T>(state: ListState<T>) {
return layout;
}

interface ListViewProps<T> extends CollectionBase<T>, DOMProps, AriaLabelingProps, StyleProps {
interface ListViewProps<T> extends CollectionBase<T>, DOMProps, AriaLabelingProps, StyleProps, MultipleSelection {
/**
* Sets the amount of vertical padding within each cell.
* @default 'regular'
*/
density?: 'compact' | 'regular' | 'spacious',
isLoading?: boolean,
renderEmptyState?: () => JSX.Element,
transitionDuration?: number
transitionDuration?: number,
onAction?: (key: Key) => void
}

function ListView<T extends object>(props: ListViewProps<T>, ref: DOMRef<HTMLDivElement>) {
let {
transitionDuration = 0
density = 'regular',
transitionDuration = 0,
onAction
} = props;
let domRef = useDOMRef(ref);
let {collection} = useListState(props);
let formatMessage = useMessageFormatter(intlMessages);
let [selectionMode, setSelectionMode] = useState(false);
jluyau marked this conversation as resolved.
Show resolved Hide resolved

let {styleProps} = useStyleProps(props);
let {direction} = useLocale();
Expand Down Expand Up @@ -95,7 +104,7 @@ function ListView<T extends object>(props: ListViewProps<T>, ref: DOMRef<HTMLDiv
layout.isLoading = props.isLoading;

return (
<ListViewContext.Provider value={{state, keyboardDelegate}}>
<ListViewContext.Provider value={{state, keyboardDelegate, onAction, selectionMode, setSelectionMode}}>
<Virtualizer
{...gridProps}
{...styleProps}
Expand All @@ -107,6 +116,7 @@ function ListView<T extends object>(props: ListViewProps<T>, ref: DOMRef<HTMLDiv
classNames(
listStyles,
'react-spectrum-ListView',
`react-spectrum-ListView--${density}`,
styleProps.className
)
}
Expand Down
Loading