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

Develop #753

Merged
merged 13 commits into from
Mar 12, 2024
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
7 changes: 7 additions & 0 deletions apps/protoform/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# protoform

## 0.1.5

### Patch Changes

- Updated dependencies [b8240a3]
- @westpac/[email protected]

## 0.1.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/protoform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "protoform",
"version": "0.1.4",
"version": "0.1.5",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
7 changes: 7 additions & 0 deletions apps/site/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# site

## 0.1.7

### Patch Changes

- Updated dependencies [b8240a3]
- @westpac/[email protected]

## 0.1.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/site/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "site",
"version": "0.1.6",
"version": "0.1.7",
"private": true,
"scripts": {
"build": "next build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ Badges come in 2 different styles: Default, used to highlight words, and Pill, u
<p className="typography-body-10 text-muted">
<em>Colours</em>
</p>
<div className="flex gap-2">
<div>
{COLORS.map(color => (
<Badge color={color} >
<Badge color={color} className="my-1 mr-2" >
{color}
</Badge>
))}
</div>
<p className="typography-body-10 text-muted">
<em>Soft</em>
</p>
<div className="flex gap-2">
<div>
{COLORS.map(color => (
<Badge color={color} soft>
<Badge color={color} soft className="my-1 mr-2">
{color}
</Badge>
))}
Expand All @@ -44,19 +44,19 @@ Badges come in 2 different styles: Default, used to highlight words, and Pill, u
<p className="typography-body-10 text-muted">
<em>Colours</em>
</p>
<div className="flex gap-2">
<div>
{COLORS.map(color => (
<Badge className="my-1" type="pill" color={color} >
<Badge className="my-1 mr-2" type="pill" color={color}>
88
</Badge>
))}
</div>
<p className="typography-body-10 text-muted">
<em>Soft</em>
</p>
<div className="flex gap-2">
<div>
{COLORS.map(color => (
<Badge className="my-1" type="pill" color={color} soft>
<Badge className="my-1 mr-2" type="pill" color={color} soft>
88
</Badge>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
When setting up your project we recommend extending `@westpac/eslint-config/nextjs` as seen below:

```html
<StaticCode language="tsx" code={`
// .eslintrc.js
module.exports = {
root: true,
extends: ['@westpac/eslint-config/nextjs'],
};
`} />
```

If you are using this in a non-Next.js project, you may need to turn off certain rules as seen below:

```html
<StaticCode language="tsx" code={`
// .eslintrc.js
module.exports = {
root: true,
extends: ['@westpac/eslint-config/nextjs'],
rules: {
'@next/next/no-html-link-for-pages': 0,
},
};
`} />
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: ESLint
description: >-
We suggest following the Westpac Group ESLint configuration.
design:
- title:
name: ESLint Configuration
slug: eslint-configuration
accessibility: []
9 changes: 7 additions & 2 deletions packages/ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const OFF = 0;

module.exports = {
root: true,
extends: ['@westpac/eslint-config'],
extends: ['@westpac/eslint-config/nextjs'],
rules: {
'@next/next/no-html-link-for-pages': OFF,
},
overrides: [
{
files: ['**/*.stories.tsx', '**/*.stories.ts'],
Expand All @@ -18,4 +23,4 @@ module.exports = {
},
},
},
};
};
6 changes: 6 additions & 0 deletions packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @westpac/ui

## 0.20.0

### Minor Changes

- b8240a3: Updated types on some components to resolve eslint errors/warnings

## 0.19.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@westpac/ui",
"version": "0.19.0",
"version": "0.20.0",
"license": "MIT",
"sideEffects": false,
"type": "module",
Expand Down
24 changes: 15 additions & 9 deletions packages/ui/src/components/accordion/accordion.component.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,47 @@
'use client';

import { useAccordion } from '@react-aria/accordion';
import { AriaAccordionProps, useAccordion } from '@react-aria/accordion';
import { filterDOMProps } from '@react-aria/utils';
import { useDOMRef } from '@react-spectrum/utils';
import { DOMProps, DOMRef } from '@react-types/shared';
import React, { Children, cloneElement, forwardRef, isValidElement } from 'react';
import { Item, type ItemProps, useTreeState } from 'react-stately';
import { Item, type ItemProps, TreeProps, useTreeState } from 'react-stately';

import { styles } from './accordion.styles.js';
import { type AccordionProps } from './accordion.types.js';
import { AccordionItem as AccordionItemContent } from './components/index.js';

function Accordion<T extends object>(
{ className, rounded = true, look = 'soft', ...props }: AccordionProps<T>,
ref: any,
ref: DOMRef<HTMLDivElement>,
) {
// react-aria doesn't allow for now to use component children when there is multiple levels
// in our case we don't need that functionality and we have to render html tags or components
// therefore as a workaround we are setting hasChildItems false for all of them
// https://github.com/adobe/react-spectrum/issues/3882
const finalProps: any = {
const finalProps = {
...props,
children: Children.map(props.children, child => {
// equal to (if (child == null || typeof child == 'string'))
if (!isValidElement(child)) return child;
return cloneElement(child, {
...(child.props as any),
...child.props,
// Adding hasChildItems false by default
hasChildItems: false,
});
}),
};
const state = useTreeState<T>(finalProps);
const state = useTreeState<T>(finalProps as TreeProps<T>);
const domRef = useDOMRef<HTMLDivElement>(ref);
const { accordionProps } = useAccordion(finalProps, state, domRef);
const { accordionProps } = useAccordion(finalProps as AriaAccordionProps<T>, state, domRef);

return (
<div {...filterDOMProps(finalProps)} {...accordionProps} ref={domRef} className={styles({ className, rounded })}>
<div
{...filterDOMProps(finalProps as DOMProps)}
{...accordionProps}
ref={domRef}
className={styles({ className, rounded })}
>
<div className="ml-[-1px] mt-[-1px]">
{[...state.collection].map(item => (
<AccordionItemContent<T> key={item.key} item={item} state={state} look={look} />
Expand All @@ -46,7 +52,7 @@ function Accordion<T extends object>(
}

const _Accordion = forwardRef(Accordion) as unknown as { displayName: string } & (<T>(
props: AccordionProps<T> & { ref?: any },
props: AccordionProps<T> & { ref?: HTMLElement },
) => ReturnType<typeof Accordion>);

_Accordion.displayName = 'Accordion';
Expand Down
53 changes: 24 additions & 29 deletions packages/ui/src/components/accordion/accordion.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const meta: Meta<typeof Accordion> = {
};

export default meta;
type Story = StoryObj<any>;
type Story = StoryObj<typeof Accordion>;

/**
* > Default usage example
Expand Down Expand Up @@ -79,34 +79,29 @@ export const LegoLook: Story = {
/**
* > Controlled example
*/
export const Controlled: Story = {
args: {
look: 'lego',
rounded: false,
},
render: ({ ...props }) => {
const [expandedKeys, setExpandedKeys] = useState<Set<Key>>();
return (
<Accordion
{...props}
expandedKeys={expandedKeys}
onExpandedChange={keys => {
setExpandedKeys(keys);
}}
>
{[
{ key: 'files', title: 'Your files' },
{ key: 'shared', title: 'Shared with you' },
{ key: 'last', title: 'Last item' },
].map(({ key, title }) => (
<AccordionItem key={key} title={title}>
<p>{title}</p>
<Button>Test</Button>
</AccordionItem>
))}
</Accordion>
);
},
export const Controlled = () => {
const [expandedKeys, setExpandedKeys] = useState<Set<Key>>();
return (
<Accordion
look="lego"
rounded={false}
expandedKeys={expandedKeys}
onExpandedChange={keys => {
setExpandedKeys(keys);
}}
>
{[
{ key: 'files', title: 'Your files' },
{ key: 'shared', title: 'Shared with you' },
{ key: 'last', title: 'Last item' },
].map(({ key, title }) => (
<AccordionItem key={key} title={title}>
<p>{title}</p>
<Button>Test</Button>
</AccordionItem>
))}
</Accordion>
);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/accordion/accordion.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { styles } from './accordion.styles.js';
import { AccordionItemProps } from './components/index.js';

type Variants = VariantProps<typeof styles>;
export type AccordionProps<T = any> = SpectrumAccordionProps<T> & {
export type AccordionProps<T = HTMLElement> = SpectrumAccordionProps<T> & {
/**
* <AccordionItem /> as a collection
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useAccordionItem } from '@react-aria/accordion';
import { AnimatePresence, LazyMotion, m } from 'framer-motion';
import React, { useRef } from 'react';
import { mergeProps, useFocusRing, useHover, useLocale } from 'react-aria';
import { Key, mergeProps, useFocusRing, useHover, useLocale } from 'react-aria';

import { ArrowLeftIcon, ArrowRightIcon } from '../../../icon/index.js';

Expand All @@ -10,7 +10,7 @@ import { type AccordionItemProps } from './accordion-item.types.js';

const loadAnimations = () => import('./accordion-item.utils.js').then(res => res.default);

export function AccordionItem<T = any>({
export function AccordionItem<T = HTMLElement>({
className,
tag: Tag = 'div',
look = 'soft',
Expand All @@ -20,8 +20,8 @@ export function AccordionItem<T = any>({
const { state, item } = props;
const { buttonProps, regionProps } = useAccordionItem<T>(props, state, ref);
const { isFocusVisible, focusProps } = useFocusRing();
const isOpen = state.expandedKeys.has(item.key as any);
const isDisabled = state.disabledKeys.has(item.key as any);
const isOpen = state.expandedKeys.has(item.key as Key);
const isDisabled = state.disabledKeys.has(item.key as Key);
const { hoverProps } = useHover({ isDisabled });
const { direction } = useLocale();
const styles = accordionItemStyles({ isOpen, isDisabled, look, isFocusVisible });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { styles } from './accordion-item.styles.js';

type Variants = VariantProps<typeof styles>;

export type AccordionItemProps<T = any> = {
export type AccordionItemProps<T = HTMLElement> = {
/**
* AccordionItem body content
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ export function Autocomplete<T extends object>({
((!state.isOpen && state.isFocused && searchProps.value.length > 0 && !state.selectedItem) ||
(state.collection.size === 0 && searchProps.value.length > 0))
);
}, [state, searchProps, noOptionsMessage]);
}, [
noOptionsMessage,
state.isOpen,
state.isFocused,
state.selectedItem,
state.collection.size,
searchProps.value.length,
]);

const iconSize = useMemo(() => {
switch (size) {
Expand Down Expand Up @@ -161,7 +168,7 @@ export function Autocomplete<T extends object>({
>
<AutocompleteListBox
{...listBoxProps}
autoFocus={listBoxProps.autoFocus as any}
autoFocus={listBoxProps.autoFocus as boolean | undefined}
listBoxRef={listBoxRef}
state={state}
/>
Expand Down
Loading
Loading