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

fix: Re-export Spectrum components for v0.85 #2332

Merged
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
14 changes: 8 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions packages/code-studio/src/styleguide/CheckboxGroups.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import { CheckboxGroup, Flex, Text } from '@deephaven/components';
// eslint-disable-next-line no-restricted-imports
import { Checkbox } from '@adobe/react-spectrum';
import SampleSection from './SampleSection';

export function CheckboxGroups(): JSX.Element {
return (
<SampleSection name="checkbox-groups">
<h2 className="ui-title">Checkbox Groups</h2>
<Flex gap="size-100" gridColumn="span 3" height="100%">
<Flex direction="column">
<Text>Single Child</Text>
<CheckboxGroup aria-label="Single Child">
<Checkbox value="Aaa">Aaa</Checkbox>
</CheckboxGroup>
</Flex>

<Flex direction="column">
<Text>Multiple Children</Text>
<CheckboxGroup aria-label="Multiple Children">
<Checkbox value="Aaa">Aaa</Checkbox>
<Checkbox value="Bbb">Bbb</Checkbox>
<Checkbox value="Ccc">Ccc</Checkbox>
</CheckboxGroup>
</Flex>

<Flex direction="column">
<Text>Mixed Children Types</Text>
<CheckboxGroup aria-label="Mixed Children Types">
{/* eslint-disable react/jsx-curly-brace-presence */}
{'String 1'}
{'String 2'}
{444}
{999}
{true}
{false}
<Checkbox>Aaa</Checkbox>
</CheckboxGroup>
</Flex>
</Flex>
</SampleSection>
);
}

export default CheckboxGroups;
2 changes: 2 additions & 0 deletions packages/code-studio/src/styleguide/StyleGuide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import SpectrumComparison from './SpectrumComparison';
import Pickers from './Pickers';
import ListViews from './ListViews';
import ErrorViews from './ErrorViews';
import CheckboxGroups from './CheckboxGroups';

const stickyProps = {
position: 'sticky',
Expand Down Expand Up @@ -117,6 +118,7 @@ function StyleGuide(): React.ReactElement {
<ItemListInputs />
<DraggableLists />
<TimeSliderInputs />
<CheckboxGroups />
<Dialog />
<Modals />
<ContextMenus />
Expand Down
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@deephaven/utils": "file:../utils",
"@fortawesome/fontawesome-svg-core": "^6.2.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"@internationalized/date": "^3.5.5",
"@react-spectrum/theme-default": "^3.5.1",
"@react-spectrum/utils": "^3.11.5",
"@react-types/radio": "^3.8.1",
Expand Down
43 changes: 43 additions & 0 deletions packages/components/src/spectrum/CheckboxGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-disable react/no-array-index-key */
import { isElementOfType } from '@deephaven/react-hooks';
import React, { type ReactNode, useMemo } from 'react';
import {
Checkbox,
CheckboxGroup as SpectrumCheckboxGroup,
type SpectrumCheckboxGroupProps,
} from '@adobe/react-spectrum';
import { ensureArray } from '@deephaven/utils';

export type CheckboxGroupProps = {
children: ReactNode;
} & Omit<SpectrumCheckboxGroupProps, 'children'>;

/**
* Augmented version of the Spectrum CheckboxGroup component that supports
* primitive item children.
*/
export function CheckboxGroup({
children,
...props
}: CheckboxGroupProps): JSX.Element {
const wrappedChildren = useMemo(
() =>
ensureArray(children).map(child =>
isElementOfType(child, Checkbox) ? (
child
) : (
<Checkbox key={String(child)} value={String(child)}>
{String(child)}
</Checkbox>
)
),
[children]
);

return (
// eslint-disable-next-line react/jsx-props-no-spreading
<SpectrumCheckboxGroup {...props}>{wrappedChildren}</SpectrumCheckboxGroup>
);
}

export default CheckboxGroup;
20 changes: 20 additions & 0 deletions packages/components/src/spectrum/dateAndTime.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import {
CalendarDate,
CalendarDateTime,
ZonedDateTime,
} from '@internationalized/date';

export {
Calendar,
type SpectrumCalendarProps as CalendarProps,
Expand All @@ -12,3 +18,17 @@ export {
TimeField,
type SpectrumTimeFieldProps as TimeFieldProps,
} from '@adobe/react-spectrum';

export type { CalendarDate, CalendarDateTime, ZonedDateTime };

// This is the type for the DatePicker value
export type DateValue = CalendarDate | CalendarDateTime | ZonedDateTime;

// This is the type for DatePicker onChange
export type MappedDateValue<T> = T extends ZonedDateTime
? ZonedDateTime
: T extends CalendarDateTime
? CalendarDateTime
: T extends CalendarDate
? CalendarDate
: never;
2 changes: 0 additions & 2 deletions packages/components/src/spectrum/forms.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export {
Checkbox as SpectrumCheckbox,
type SpectrumCheckboxProps,
CheckboxGroup,
type SpectrumCheckboxGroupProps as CheckboxGroupProps,
Form,
type SpectrumFormProps as FormProps,
NumberField,
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/spectrum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export * from './picker';
export * from './Heading';
export * from './Text';
export * from './View';
export * from './CheckboxGroup';

/**
* Custom DH spectrum utils
Expand Down
1 change: 1 addition & 0 deletions tests/styleguide.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const sampleSectionIds: string[] = [
'sample-section-spectrum-overlays',
'sample-section-spectrum-well',
'sample-section-error-views',
'sample-section-checkbox-groups',
];
const buttonSectionIds: string[] = [
'sample-section-buttons-regular',
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading