Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export * from './SelectValueList';
export * from './shortcuts';
export { default as SocketedButton } from './SocketedButton';
export * from './spectrum';
export * from './SpectrumUtils';
export * from './spectrum/utils';
export * from './TableViewEmptyState';
export * from './TextWithTooltip';
export * from './theme';
Expand Down
25 changes: 25 additions & 0 deletions packages/components/src/spectrum/Heading.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { render } from '@testing-library/react';
import { Heading } from './Heading';

describe('Heading', () => {
it('mounts and unmounts', () => {
render(<Heading>{null}</Heading>);
});

it('renders without color', () => {
const { getByTestId } = render(<Heading data-testid="Heading" />);
const HeadingElement = getByTestId('Heading');
expect(HeadingElement).toBeInTheDocument();
});

it('renders with color', () => {
const color = 'red';
const { getByTestId } = render(
<Heading data-testid="Heading" color={color} />
);
const HeadingElement = getByTestId('Heading');
expect(HeadingElement).toBeInTheDocument();
expect(HeadingElement).toHaveStyle(`color: ${color}`);
});
});
39 changes: 39 additions & 0 deletions packages/components/src/spectrum/Heading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable react/jsx-props-no-spreading */
import {
Heading as SpectrumHeading,
type HeadingProps as SpectrumHeadingProps,
} from '@adobe/react-spectrum';
import { type ColorValue, colorValueStyle } from '../theme/colorUtils';

export type HeadingProps = SpectrumHeadingProps & {
color?: ColorValue;
};

/**
* A Heading component that re-exports the Spectrum Heading component.
* It overrides ColorValues to accept CSS color strings and custom
* variable names from our color paletee and semantic colors.
*
* @param props The props for the Heading component
* @returns The Heading component
*
*/

export function Heading(props: HeadingProps): JSX.Element {
const { color, UNSAFE_style, ...rest } = props;
if (color != null) {
return (
<SpectrumHeading
{...(rest as SpectrumHeadingProps)}
Comment thread
dsmmcken marked this conversation as resolved.
Outdated
UNSAFE_style={{
...UNSAFE_style,
color: colorValueStyle(color),
}}
/>
);
}

return <SpectrumHeading {...(props as SpectrumHeadingProps)} />;
Comment thread
dsmmcken marked this conversation as resolved.
Outdated
}

export default Heading;
27 changes: 27 additions & 0 deletions packages/components/src/spectrum/Text.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import { render } from '@testing-library/react';
import { Text } from './Text';

describe('Text', () => {
it('mounts and unmounts', () => {
render(<Text>test</Text>);
});

it('renders without color', () => {
const { getByTestId } = render(<Text data-testid="Text">test</Text>);
const TextElement = getByTestId('Text');
expect(TextElement).toBeInTheDocument();
});

it('renders with color', () => {
const color = 'red';
const { getByTestId } = render(
<Text data-testid="Text" color={color}>
test
</Text>
);
const TextElement = getByTestId('Text');
expect(TextElement).toBeInTheDocument();
expect(TextElement).toHaveStyle(`color: ${color}`);
});
});
39 changes: 39 additions & 0 deletions packages/components/src/spectrum/Text.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable react/jsx-props-no-spreading */
import {
Text as SpectrumText,
type TextProps as SpectrumTextProps,
} from '@adobe/react-spectrum';
import { type ColorValue, colorValueStyle } from '../theme/colorUtils';

export type TextProps = SpectrumTextProps & {
color?: ColorValue;
};

/**
* A Text component that re-exports the Spectrum Text component.
* It overrides ColorValues to accept CSS color strings and custom
* variable names from our color paletee and semantic colors.
*
* @param props The props for the Text component
* @returns The Text component
*
*/

export function Text(props: TextProps): JSX.Element {
const { color, UNSAFE_style, ...rest } = props;
if (color != null) {
return (
<SpectrumText
{...(rest as SpectrumTextProps)}
Comment thread
dsmmcken marked this conversation as resolved.
Outdated
UNSAFE_style={{
...UNSAFE_style,
color: colorValueStyle(color),
}}
/>
);
}

return <SpectrumText {...(props as SpectrumTextProps)} />;
Comment thread
dsmmcken marked this conversation as resolved.
Outdated
}

export default Text;
25 changes: 25 additions & 0 deletions packages/components/src/spectrum/View.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { render } from '@testing-library/react';
import { View } from './View';

describe('View', () => {
it('mounts and unmounts', () => {
render(<View>{null}</View>);
});

it('renders without backgroundColor', () => {
const { getByTestId } = render(<View data-testid="view" />);
const viewElement = getByTestId('view');
expect(viewElement).toBeInTheDocument();
});

it('renders with backgroundColor', () => {
const backgroundColor = 'red';
const { getByTestId } = render(
<View data-testid="view" backgroundColor={backgroundColor} />
);
const viewElement = getByTestId('view');
expect(viewElement).toBeInTheDocument();
expect(viewElement).toHaveStyle(`background-color: ${backgroundColor}`);
});
});
39 changes: 39 additions & 0 deletions packages/components/src/spectrum/View.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable react/jsx-props-no-spreading */
import {
View as SpectrumView,
type ViewProps as SpectrumViewProps,
} from '@adobe/react-spectrum';
import { type ColorValue, colorValueStyle } from '../theme/colorUtils';

export type ViewProps = Omit<SpectrumViewProps<6>, 'backgroundColor'> & {
backgroundColor?: ColorValue;
};

/**
* A View component that re-exports the Spectrum View component.
* However, it overrides ColorValues to accept CSS color strings and
* our custom variable names from our color paletee and semantic colors.
*
* @param props The props for the View component
* @returns The View component
*
*/

export function View(props: ViewProps): JSX.Element {
const { backgroundColor, UNSAFE_style, ...rest } = props;
if (backgroundColor != null) {
return (
<SpectrumView
{...(rest as SpectrumViewProps<6>)}
Comment thread
dsmmcken marked this conversation as resolved.
Outdated
UNSAFE_style={{
...UNSAFE_style,
backgroundColor: colorValueStyle(backgroundColor),
}}
/>
);
}

return <SpectrumView {...(props as SpectrumViewProps<6>)} />;
}

export default View;
6 changes: 0 additions & 6 deletions packages/components/src/spectrum/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,12 @@ export {
type SpectrumDividerProps as DividerProps,
Footer,
type FooterProps,
Heading,
type HeadingProps,
IllustratedMessage,
type SpectrumIllustratedMessageProps as IllustratedMessageProps,
Image,
type SpectrumImageProps as ImageProps,
Keyboard,
type KeyboardProps,
Text,
type TextProps,
View,
type ViewProps,
Well,
type SpectrumWellProps as WellProps,
} from '@adobe/react-spectrum';
8 changes: 8 additions & 0 deletions packages/components/src/spectrum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,11 @@ export * from './status';
* Custom DH components wrapping React Spectrum components.
*/
export * from './picker';
export * from './Heading';
export * from './Text';
export * from './View';

/**
* Custom DH spectrum utils
*/
export * from './utils';
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from './PickerUtils';
import type { PickerProps } from './Picker';
import { Item, Section } from '../shared';
import { Text } from '../content';
import { Text } from '../Text';

beforeEach(() => {
expect.hasAssertions();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { themeDHDefault } from './SpectrumUtils';
import { themeDHDefault } from './utils';

describe('themeDHDefault', () => {
it('should merge Spectrum default with DH custom styles', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { theme } from '@react-spectrum/theme-default';
import { themeSpectrumClassesCommon } from './theme/theme-spectrum';
import { themeSpectrumClassesCommon } from '../theme/theme-spectrum';

const { global, light, dark, medium, large } = theme;

Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/theme/SpectrumThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactNode, useState } from 'react';
import { Provider } from '@adobe/react-spectrum';
import type { Theme } from '@react-types/provider';
import shortid from 'shortid';
import { themeDHDefault } from '../SpectrumUtils';
import { themeDHDefault } from '../spectrum/utils';

export interface SpectrumThemeProviderProps {
children: ReactNode;
Expand Down
14 changes: 14 additions & 0 deletions packages/components/src/theme/colorUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { colorValueStyle } from './colorUtils';

describe('ColorValues', () => {
test('should return the correct color style', () => {
// dh-color variables
expect(colorValueStyle('blue-1000')).toBe('var(--dh-color-blue-1000)');
Comment thread
dsmmcken marked this conversation as resolved.
expect(colorValueStyle('accent-1000')).toBe('var(--dh-color-accent-1000)');
expect(colorValueStyle('bg')).toBe('var(--dh-color-bg)');
// pass-through variables
expect(colorValueStyle('red')).toBe('red');
expect(colorValueStyle('rgb(255, 0, 0)')).toBe('rgb(255, 0, 0)');
expect(colorValueStyle('#ff0000')).toBe('#ff0000');
});
});
Loading