Skip to content

Commit

Permalink
refactor: Updates the docs to correctly generate the Table API for co…
Browse files Browse the repository at this point in the history
…mponents
  • Loading branch information
matuzalemsteles committed Jan 10, 2025
1 parent aeb34dd commit 84b1a8c
Show file tree
Hide file tree
Showing 199 changed files with 2,086 additions and 2,157 deletions.
6 changes: 3 additions & 3 deletions packages/clay-alert/docs/alert.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ packageNpm: '@clayui/alert'
packageUse: "import Alert from '@clayui/alert';"
packageTypes:
[
'clay-alert/src',
'clay-alert/src/footer',
'clay-alert/src/toast-container',
'clay-alert/src/index.tsx',
'clay-alert/src/Footer.tsx',
'clay-alert/src/ToastContainer.tsx',
]
---

Expand Down
3 changes: 1 addition & 2 deletions packages/clay-alert/src/ToastContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import React from 'react';

import {IClayAlertProps} from './index';

export interface IToastContainerProps
extends React.HTMLAttributes<HTMLDivElement> {
interface IToastContainerProps extends React.HTMLAttributes<HTMLDivElement> {
/**
* Children of the ToastContainer must be a ClayAlert
*/
Expand Down
12 changes: 2 additions & 10 deletions packages/clay-alert/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,7 @@ const useAutoClose = (autoClose?: boolean | number, onClose = () => {}) => {
};
};

export type DisplayType =
| 'danger'
| 'info'
| 'secondary'
| 'success'
| 'warning';

export interface IClayAlertProps
interface IClayAlertProps
extends Omit<React.HTMLAttributes<HTMLDivElement>, 'role'> {
/**
* A React Component to render the alert actions.
Expand All @@ -89,7 +82,7 @@ export interface IClayAlertProps
/**
* Determines the style of the alert.
*/
displayType?: DisplayType;
displayType?: 'danger' | 'info' | 'secondary' | 'success' | 'warning';

/**
* Flag to indicate if close icon should be show. This prop is used in
Expand Down Expand Up @@ -236,5 +229,4 @@ ClayAlert.displayName = 'ClayAlert';
ClayAlert.Footer = ClayAlertFooter;
ClayAlert.ToastContainer = ClayToastContainer;

export {ClayAlertFooter, ClayToastContainer, ClayAlert};
export default ClayAlert;
3 changes: 2 additions & 1 deletion packages/clay-autocomplete/docs/autocomplete.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ description: 'An autocomplete text field is an input that offers the user text s
lexiconDefinition: 'https://liferay.design/lexicon/core-components/forms/text-input-variations/'
packageNpm: '@clayui/autocomplete'
packageUse: "import Autocomplete from '@clayui/autocomplete';"
packageTypes: ['clay-autocomplete/src', 'clay-autocomplete/src/item']
packageTypes:
['clay-autocomplete/src/index.tsx', 'clay-autocomplete/src/Item.tsx']
---

## Example
Expand Down
47 changes: 45 additions & 2 deletions packages/clay-autocomplete/src/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,51 @@ import React, {useCallback} from 'react';

import {useAutocompleteState} from './Context';

export interface IProps extends React.ComponentProps<typeof DropDown.Item> {
interface IProps
extends React.HTMLAttributes<
HTMLSpanElement | HTMLButtonElement | HTMLAnchorElement
> {
/**
* Flag that indicates if item is selected.
*/
active?: boolean;

/**
* Flag that indicates if item is disabled or not.
*/
disabled?: boolean;

/**
* @ignore
*/
'data-index'?: number;

/**
* Path for item to link to.
*/
href?: string;

/**
* Sets the role accessibility property of the item. Set the item's
* container (<li />) role use the role="" prop instead of roleItem="".
*/
roleItem?: string;

/**
* Path to icon spritemap from clay-css.
*/
spritemap?: string;

/**
* Flag that indicates if there is an icon symbol on the left side.
*/
symbolLeft?: string;

/**
* Flag that indicates if there is an icon symbol on the right side.
*/
symbolRight?: string;

/**
* The item content.
*/
Expand Down Expand Up @@ -156,5 +200,4 @@ const Item = React.forwardRef<HTMLLIElement, IProps>(

Item.displayName = 'Item';

export {Item};
export default Item;
137 changes: 137 additions & 0 deletions packages/clay-autocomplete/src/LegacyAutocomplete.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* SPDX-FileCopyrightText: © 2019 Liferay, Inc. <https://liferay.com>
* SPDX-License-Identifier: BSD-3-Clause
*/

import {ClayInput} from '@clayui/form';
import {FocusScope} from '@clayui/shared';
import React from 'react';

import {Autocomplete} from './Autocomplete';
import {LegacyContext} from './Context';
import DropDown from './DropDown';
import Input from './Input';
import Item from './Item';
import LoadingIndicator from './LoadingIndicator';

import type {IProps as IAutocompleteProps} from './Autocomplete';

const AutocompleteMarkup = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({children, ...otherProps}, ref) => (
<ClayInput.Group {...otherProps} ref={ref}>
<ClayInput.GroupItem>{children}</ClayInput.GroupItem>
</ClayInput.Group>
));

AutocompleteMarkup.displayName = 'ClayAutocompleteMarkup';

/**
* Temporary helper function to determine which version of autocomplete
* is being used.
*/
const hasItems = (children?: React.ReactNode) => {
if (!children) {
return [];
}

return React.Children.map(children, (child) => {
if (
React.isValidElement(child) &&
// @ts-ignore
child.type.displayName === 'Item'
) {
return true;
}

return false;
}).filter(Boolean);
};

interface IProps<T> extends IAutocompleteProps<T> {
/**
* Div component to render. It can be a one component that will replace the markup.
*/
component?: React.ForwardRefExoticComponent<any>;
}

interface IForwardRef<T, P = {}>
extends React.ForwardRefExoticComponent<P & React.RefAttributes<T>> {
DropDown: typeof DropDown;
Input: typeof Input;
Item: typeof Item;
LoadingIndicator: typeof LoadingIndicator;
}

function forwardRef<T, P = {}>(component: React.RefForwardingComponent<T, P>) {
return React.forwardRef<T, P>(component) as IForwardRef<T, P>;
}

const ClayAutocomplete = forwardRef(
<T extends Record<string, any> | string | number>(
{
children,
className,
component: Component = AutocompleteMarkup,
...otherProps
}: IProps<T>,
ref: React.Ref<HTMLInputElement>
) => {
const containerElementRef = React.useRef<null | HTMLDivElement>(null);
const [loading, setLoading] = React.useState(false);

const isNewBehavior =
hasItems(children).length >= 1 || children instanceof Function;

const Container = isNewBehavior ? React.Fragment : FocusScope;

return (
<Container>
<Component
{...(isNewBehavior ? {} : otherProps)}
className={className}
ref={(r: any) => {
if (r) {
containerElementRef.current = r;

if (typeof ref === 'function') {
ref(r);
} else if (ref !== null) {
(ref as React.MutableRefObject<any>).current =
r;
}
}
}}
>
{isNewBehavior ? (
<Autocomplete<T>
containerElementRef={containerElementRef}
{...otherProps}
>
{children}
</Autocomplete>
) : (
<LegacyContext.Provider
value={{
containerElementRef,
loading,
onLoadingChange: (loading: boolean) =>
setLoading(loading),
}}
>
{children}
</LegacyContext.Provider>
)}
</Component>
</Container>
);
}
);

ClayAutocomplete.DropDown = DropDown;
ClayAutocomplete.Input = Input;
ClayAutocomplete.Item = Item;
ClayAutocomplete.LoadingIndicator = LoadingIndicator;

export default ClayAutocomplete;
Loading

0 comments on commit 84b1a8c

Please sign in to comment.