Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Forward ref components #2803

Merged
merged 46 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
21ba279
✨ `Bullet`: implement ref forwarding
lowiebenoot Nov 6, 2023
723f620
✨ `Label`: implement ref forwarding
lowiebenoot Nov 6, 2023
3187e7d
✨ `MarketingMenuItem`: implement ref forwarding
lowiebenoot Nov 6, 2023
b6be0a2
✨ `MenuItem`: implement ref forwarding
lowiebenoot Nov 6, 2023
b55efa0
✨ `MarketingStatusLabel`: implement ref forwarding
lowiebenoot Nov 6, 2023
88c8c75
✨ `AdvancedCollapsible`: implement ref forwarding
lowiebenoot Nov 6, 2023
686c279
✨ `Banner`: implement ref forwarding
lowiebenoot Nov 6, 2023
5c7bde7
✨ `Container`: implement ref forwarding
lowiebenoot Nov 6, 2023
406d2b1
✨ `Counter`: implement ref forwarding
lowiebenoot Nov 6, 2023
cf3c0f7
✨ `DataGrid`: implement ref forwarding
lowiebenoot Nov 6, 2023
cb2cd7d
✨ `DatePicker`: implement ref forwarding
lowiebenoot Nov 6, 2023
6e12077
✨ `DetailPage`: implement ref forwarding
lowiebenoot Nov 6, 2023
8dd0a77
✨ `EmptyState`: implement ref forwarding
lowiebenoot Nov 6, 2023
6bd7e12
✨ `Grid.GridItem`: implement ref forwarding
lowiebenoot Nov 6, 2023
c2dae02
✨ `Island`: implement ref forwarding
lowiebenoot Nov 6, 2023
41b613d
✨ `LabelValuePair`: implement ref forwarding
lowiebenoot Nov 6, 2023
b651a0f
✨ `LoadingBar`: implement ref forwarding
lowiebenoot Nov 6, 2023
f24e584
✨ `MarketingButtonGroup`: implement ref forwarding
lowiebenoot Nov 6, 2023
2c4c844
✨ `MarketingLockBadge`: implement ref forwarding
lowiebenoot Nov 6, 2023
d275ad1
✨ `MarketingMarker`: implement ref forwarding
lowiebenoot Nov 6, 2023
763c9a2
✨ `MarketingHeading1`: implement ref forwarding
lowiebenoot Nov 6, 2023
90fd119
✨ `MarketingHeading2`: implement ref forwarding
lowiebenoot Nov 6, 2023
cd1b09b
✨ `Message`: implement ref forwarding
lowiebenoot Nov 6, 2023
bf9042b
✨ `OverviewPage`: implement ref forwarding
lowiebenoot Nov 6, 2023
8fef735
✨ `Pagination`: implement ref forwarding
lowiebenoot Nov 6, 2023
443a736
✨ `ProgressTracker`: implement ref forwarding
lowiebenoot Nov 6, 2023
ca73362
✨ `RadioButton`: implement ref forwarding
lowiebenoot Nov 6, 2023
f445060
✨ `SplitButton`: implement ref forwarding
lowiebenoot Nov 6, 2023
b6200de
✨ `TabGroup`: implement ref forwarding
lowiebenoot Nov 6, 2023
db2832e
✨ `Tag`: implement ref forwarding
lowiebenoot Nov 6, 2023
80660ea
✨ `Toast`: implement ref forwarding
lowiebenoot Nov 6, 2023
d618f2b
✨ `ToastContainer`: implement ref forwarding
lowiebenoot Nov 6, 2023
55ae972
✨ `Toggle`: implement ref forwarding
lowiebenoot Nov 6, 2023
03d5d9a
🔥 `Toggle`: remove unused inputRef
lowiebenoot Nov 6, 2023
d1ce2f5
✨ `Marker`: implement ref forwarding
lowiebenoot Nov 6, 2023
dabd434
✨ `Monospaced`: implement ref forwarding
lowiebenoot Nov 6, 2023
3bbc925
✨ `ErrorText`: implement ref forwarding
lowiebenoot Nov 6, 2023
8edda78
✨ `HelpText`: implement ref forwarding
lowiebenoot Nov 6, 2023
b4f65c0
✨ `SuccessText`: implement ref forwarding
lowiebenoot Nov 6, 2023
d6e8f55
✨ `WarningText`: implement ref forwarding
lowiebenoot Nov 6, 2023
b84d215
✨ `ValidationText`: implement ref forwarding
lowiebenoot Nov 6, 2023
80aceac
✨ `WysiwygEditor`: implement ref forwarding
lowiebenoot Nov 6, 2023
3b1bb17
🏷️ Fix types on components with subcomponents
lowiebenoot Nov 6, 2023
3c3f840
📝 Update changelog
lowiebenoot Nov 6, 2023
c69aa19
🔖 Bump version
lowiebenoot Nov 6, 2023
c3e63d3
🐛 Forgot to actually use the forwarded ref
lowiebenoot Nov 6, 2023
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
56 changes: 51 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,64 @@

### Removed

## [23.0.0] - 2023-10-30

### Removed

- `Tooltip`: removed `horizontal` and `vertical` positions from the `tooltipPosition` options. Tooltips will still render to the opposite side in case there is not enough space on the chosen position. ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2796](https://github.com/teamleadercrm/ui/pull/2796)`
## [23.1.0] - 2023-11-06

### Changed

- `WysiwygEditor`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `ValidationText`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `WarningText`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `SuccessText`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `HelpText`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `ErrorText`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Monospaced`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Marker`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Toggle`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `ToastContainer`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Toast`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Tag`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `TabGroup`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `SplitButton`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `RadioButton`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `ProgressTracker`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Pagination`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `OverviewPage`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Message`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `MarketingHeading2`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `MarketingHeading1`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `MarketingMarker`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `MarketingLockBadge`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `MarketingButtonGroup`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `LoadingBar`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `LabelValuePair`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Island`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `GridItem`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `EmptyState`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `DetailPage`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `DatePicker`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `DataGrid`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Counter`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Container`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Banner`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `AdvancedCollapsible`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `MarketingStatusLabel`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `MenuItem`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `MarketingMenuItem`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Label`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)
- `Bullet`: implementeed ref forwarding ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2803](https://github.com/teamleadercrm/ui/pull/2803)

## [23.0.1] - 2023-10-30

### Fixed

- `Tooltip`: added missing `data-teamleader-ui="tooltip"` attribute ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2799](https://github.com/teamleadercrm/ui/pull/2799)`

## [23.0.0] - 2023-10-30

### Removed

- `Tooltip`: removed `horizontal` and `vertical` positions from the `tooltipPosition` options. Tooltips will still render to the opposite side in case there is not enough space on the chosen position. ([@lowiebenoot](https://github.com/lowiebenoot)) in [#2796](https://github.com/teamleadercrm/ui/pull/2796)`

## [22.3.5] - 2023-10-18

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@teamleader/ui",
"description": "Teamleader UI library",
"version": "23.0.1",
"version": "23.1.0",
"author": "Teamleader <[email protected]>",
"bugs": {
"url": "https://github.com/teamleadercrm/ui/issues"
Expand Down
75 changes: 38 additions & 37 deletions src/components/advancedCollapsible/AdvancedCollapsible.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode, useState } from 'react';
import React, { ReactNode, forwardRef, useState } from 'react';
import { TextBody, Heading3 } from '../typography';
import Icon from '../icon';
import Box, { pickBoxProps } from '../box';
Expand Down Expand Up @@ -26,46 +26,47 @@ export interface AdvancedCollapsibleProps extends Omit<BoxProps, 'size'> {
onChange?: (collapsed: boolean, event: React.MouseEvent) => void;
}

const AdvancedCollapsible: GenericComponent<AdvancedCollapsibleProps> = ({
children,
color = 'teal',
indent = true,
size = 'medium',
title,
defaultIsCollapsed = true,
onChange,
...others
}) => {
const [collapsed, setCollapsed] = useState(defaultIsCollapsed);
const AdvancedCollapsible: GenericComponent<AdvancedCollapsibleProps> = forwardRef<
HTMLDivElement,
AdvancedCollapsibleProps
>(
(
{ children, color = 'teal', indent = true, size = 'medium', title, defaultIsCollapsed = true, onChange, ...others },
ref,
) => {
const [collapsed, setCollapsed] = useState(defaultIsCollapsed);

const boxProps = pickBoxProps(others);
const TitleElement = size === 'large' ? Heading3 : TextBody;
const boxProps = pickBoxProps(others);
const TitleElement = size === 'large' ? Heading3 : TextBody;

const handleTitleClick = (event: React.MouseEvent) => {
if (onChange) {
onChange(!collapsed, event);
}
const handleTitleClick = (event: React.MouseEvent) => {
if (onChange) {
onChange(!collapsed, event);
}

setCollapsed(!collapsed);
};
setCollapsed(!collapsed);
};

return (
<Box data-teamleader-ui="advanced-collapsible">
<Box className={theme['title']} display="flex" alignItems="center" onClick={handleTitleClick} {...boxProps}>
<Icon color={color} tint="darkest">
{collapsed ? <IconChevronRightSmallOutline /> : <IconChevronDownSmallOutline />}
</Icon>
<TitleElement color={color} marginLeft={2} tint="darkest">
{size === 'medium' ? <strong>{title}</strong> : title}
</TitleElement>
</Box>
{!collapsed && (
<Box {...(indent && { className: theme['children-indent'] })} marginTop={2}>
{children}
return (
<Box data-teamleader-ui="advanced-collapsible" ref={ref}>
<Box className={theme['title']} display="flex" alignItems="center" onClick={handleTitleClick} {...boxProps}>
<Icon color={color} tint="darkest">
{collapsed ? <IconChevronRightSmallOutline /> : <IconChevronDownSmallOutline />}
</Icon>
<TitleElement color={color} marginLeft={2} tint="darkest">
{size === 'medium' ? <strong>{title}</strong> : title}
</TitleElement>
</Box>
)}
</Box>
);
};
{!collapsed && (
<Box {...(indent && { className: theme['children-indent'] })} marginTop={2}>
{children}
</Box>
)}
</Box>
);
},
);

AdvancedCollapsible.displayName = 'AdvancedCollapsible';

export default AdvancedCollapsible;
75 changes: 37 additions & 38 deletions src/components/banner/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { forwardRef } from 'react';
import cx from 'classnames';

import Box, { BoxProps, Padding } from '../box';
Expand Down Expand Up @@ -30,43 +30,42 @@ export interface BannerProps extends Omit<BoxProps, 'size'> {
size?: Exclude<(typeof SIZES)[number], 'tiny' | 'smallest' | 'hero' | 'fullscreen'>;
}

const Banner = ({
children,
className,
color = 'white',
size = 'medium',
icon,
onClose,
fullWidth,
...others
}: BannerProps) => {
const classNames = cx(className, theme[color], theme['banner'], { [theme['banner_full-width']]: fullWidth });
const Banner = forwardRef<HTMLElement, BannerProps>(
(
{ children, className, color = 'white', size = 'medium', icon, onClose, fullWidth, ...others }: BannerProps,
ref,
) => {
const classNames = cx(className, theme[color], theme['banner'], { [theme['banner_full-width']]: fullWidth });

return (
<Box
data-teamleader-ui="banner"
className={classNames}
color={color}
padding={PADDINGS[size]}
borderRadius={fullWidth ? 'square' : 'rounded'}
{...others}
>
<div className={theme['inner']}>
{icon && <span className={theme['icon']}>{icon}</span>}
<Box flex={1} element="span" paddingRight={onClose && 7}>
{children}
</Box>
{onClose && (
<IconButton
className={theme['close-button']}
icon={<IconCloseMediumOutline />}
color={color === 'white' ? 'neutral' : color}
onClick={onClose}
/>
)}
</div>
</Box>
);
};
return (
<Box
data-teamleader-ui="banner"
className={classNames}
color={color}
padding={PADDINGS[size]}
borderRadius={fullWidth ? 'square' : 'rounded'}
{...others}
ref={ref}
>
<div className={theme['inner']}>
{icon && <span className={theme['icon']}>{icon}</span>}
<Box flex={1} element="span" paddingRight={onClose && 7}>
{children}
</Box>
{onClose && (
<IconButton
className={theme['close-button']}
icon={<IconCloseMediumOutline />}
color={color === 'white' ? 'neutral' : color}
onClick={onClose}
/>
)}
</div>
</Box>
);
},
);

Banner.displayName = 'Banner';

export default Banner;
16 changes: 9 additions & 7 deletions src/components/bullet/Bullet.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { PureComponent } from 'react';
import React, { forwardRef } from 'react';
import Box from '../box';
import cx from 'classnames';
import theme from './theme.css';
import { BoxProps } from '../box/Box';
import { COLORS, SIZES, TINTS } from '../../constants';
import { GenericComponent } from '../../@types/types';

export interface BulletProps extends Omit<BoxProps, 'size' | 'ref'> {
/** A border color to give to the counter */
Expand All @@ -18,9 +19,8 @@ export interface BulletProps extends Omit<BoxProps, 'size' | 'ref'> {
size?: Exclude<(typeof SIZES)[number], 'tiny' | 'fullscreen' | 'smallest' | 'hero'>;
}

class Bullet extends PureComponent<BulletProps> {
render() {
const { className, color = 'neutral', size = 'medium', borderColor, borderTint, ...others } = this.props;
const Bullet: GenericComponent<BulletProps> = forwardRef<HTMLElement, BulletProps>(
({ className, color = 'neutral', size = 'medium', borderColor, borderTint, ...others }, ref) => {
const classNames = cx(
theme['bullet'],
theme[color],
Expand All @@ -32,8 +32,10 @@ class Bullet extends PureComponent<BulletProps> {
className,
);

return <Box data-teamleader-ui="bullet" className={classNames} element="span" {...others} />;
}
}
return <Box data-teamleader-ui="bullet" className={classNames} element="span" ref={ref} {...others} />;
},
);

Bullet.displayName = 'Bullet';

export default Bullet;
34 changes: 19 additions & 15 deletions src/components/container/Container.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode } from 'react';
import React, { ReactNode, forwardRef } from 'react';
import Box from '../box';
import cx from 'classnames';
import theme from './theme.css';
Expand All @@ -11,20 +11,24 @@ export interface ContainerProps extends Omit<BoxProps, 'ref'> {
fixed?: boolean;
}

const Container: GenericComponent<ContainerProps> = ({ children, className, fixed, ...others }) => {
const classNames = cx(
theme['container'],
{
[theme['is-fixed']]: fixed,
},
className,
);
const Container: GenericComponent<ContainerProps> = forwardRef<HTMLElement, ContainerProps>(
({ children, className, fixed, ...others }, ref) => {
const classNames = cx(
theme['container'],
{
[theme['is-fixed']]: fixed,
},
className,
);

return (
<Box data-teamleader-ui="container" {...others} boxSizing="content-box" className={classNames}>
{children}
</Box>
);
};
return (
<Box data-teamleader-ui="container" {...others} boxSizing="content-box" className={classNames} ref={ref}>
{children}
</Box>
);
},
);

Container.displayName = 'Container';

export default Container;
Loading