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

add deprecation warnings to components #1288

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
1 change: 1 addition & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const preview = {
},
options: {
storySort: {
method: 'alphabetical',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow amazing it was that simple

order: ['Foundations', 'Components'],
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/CardStack/CardStack.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import CardStack from './CardStack';
import mdx from './CardStack.mdx';

export default {
title: 'Layouts/CardStack',
title: 'Components/CardStack',
component: CardStack,
parameters: {
docs: {
Expand Down
4 changes: 4 additions & 0 deletions src/Container/Col.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
type ColProps as ReactBootstrapColProps,
} from 'react-bootstrap';

import { useDeprecationWarning } from 'src/utils';

export type ColProps = {
/**
You can use a custom element for this component
Expand Down Expand Up @@ -66,6 +68,8 @@ export function Col({
bsPrefix = 'col',
...props
}: ColProps) {
useDeprecationWarning({ componentName: 'Col', message: 'Please use FlexContainer instead.' });

return (
<ReactBootstrapCol
as={as}
Expand Down
8 changes: 4 additions & 4 deletions src/Container/Container.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { ArgTypes, Canvas } from '@storybook/blocks';
import { Canvas } from '@storybook/blocks';
import Container from './Container';
import * as ComponentStories from './Container.stories';

# Container
# Container (Deprecated)

<b>⚠️ Deprecated: please use <code>FlexContainer</code> instead</b>

<h4>
A high level grid system to help create responsive application layouts.
Expand All @@ -25,8 +27,6 @@ There are six default breakpoints, sometimes referred to as grid tiers, for buil

<Canvas of={ComponentStories.Default} />

<ArgTypes of={Container} />

## Stories

### Default
Expand Down
2 changes: 1 addition & 1 deletion src/Container/Container.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Col, Container, Row } from '.';
import mdx from './Container.mdx';

export default {
title: 'Layouts/Container',
title: 'Deprecated/Container',
component: Container,
parameters: {
docs: {
Expand Down
4 changes: 4 additions & 0 deletions src/Container/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
type ContainerProps as ReactBootstrapContainerProps,
} from 'react-bootstrap';

import { useDeprecationWarning } from 'src/utils';

export type ContainerProps = {
/**
You can use a custom element for this component
Expand All @@ -30,6 +32,8 @@ export function Container({
bsPrefix = 'container',
...props
}: ContainerProps) {
useDeprecationWarning({ componentName: 'Container', message: 'Please use FlexContainer instead.' });

return (
<ReactBootstrapContainer
as={as}
Expand Down
4 changes: 4 additions & 0 deletions src/Container/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
type RowProps as ReactBootstrapRowProps,
} from 'react-bootstrap';

import { useDeprecationWarning } from 'src/utils';

export type RowProps = {
/**
You can use a custom element for this component
Expand Down Expand Up @@ -66,6 +68,8 @@ export function Row({
bsPrefix = 'row',
...props
}: RowProps) {
useDeprecationWarning({ componentName: 'Row', message: 'Please use FlexContainer instead.' });

return (
<ReactBootstrapRow
as={as}
Expand Down
24 changes: 3 additions & 21 deletions src/Flex/Flex.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ArgTypes, Canvas } from '@storybook/blocks';
import { Canvas } from '@storybook/blocks';
import Flex from './Flex';
import * as ComponentStories from './Flex.stories';

# Flex
# Flex (Deprecated)

##
<b>⚠️ Deprecated: please use <code>FlexContainer</code> instead</b>

<h4>
Flex is a utility component for creating consistent spacing between items. Use this for quick alignment and spacing in your layouts.
Expand All @@ -19,21 +19,3 @@ Flexbox CSS properties in the following documentation:
</ul>

<Canvas of={ComponentStories.Default} />

## Props

<ArgTypes of={Flex} />

## Stories

### Default

<Canvas of={ComponentStories.Default} />

### Flex Container

<Canvas of={ComponentStories.FlexContainer} />

### Flex Item

<Canvas of={ComponentStories.FlexItem} />
8 changes: 4 additions & 4 deletions src/Flex/Flex.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import type { Meta, StoryObj } from '@storybook/react';
import Card from '../Card';
import Flex from './Flex';

import mdx from './Flex.mdx';

const meta: Meta<typeof Flex> = {
component: Flex,
parameters: {
docs: {
description: {
component: 'Flex is a utility component for creating consistent spacing between items. Use this for quick alignment and spacing in your layouts.',
},
page: mdx,
},
},
title: 'Layouts/Flex',
title: 'Deprecated/Flex',
};

export default meta;
Expand Down
4 changes: 4 additions & 0 deletions src/Flex/Flex.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ReactNode, ElementType, createElement } from 'react';
import classNames from 'classnames';

import { useDeprecationWarning } from 'src/utils';

import styles from './Flex.module.scss';

export interface FlexProps {
Expand Down Expand Up @@ -63,6 +65,8 @@ function Flex({
width,
...props
}: FlexProps) {
useDeprecationWarning({ componentName: 'Flex', message: 'Please use FlexContainer instead.' });

// Defined flex properties as strings
const flexClasses = [
container ? styles[`flex-container`] : styles.container,
Expand Down
4 changes: 1 addition & 3 deletions src/IconCell/IconCell.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { ArgTypes, Canvas } from '@storybook/blocks';
import IconCell from './IconCell';
import * as ComponentStories from './IconCell.stories';

# Icon Cell

##
# Icon Cell (Deprecated)

<h4>
An icon with a colored background used to draw more attention to surrounding elements.
Expand Down
2 changes: 1 addition & 1 deletion src/IconCell/IconCell.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import IconCell from '.';
import mdx from './IconCell.mdx';

export default {
title: 'Components/IconCell',
title: 'Deprecated/IconCell',
component: IconCell,
parameters: {
docs: {
Expand Down
4 changes: 4 additions & 0 deletions src/IconCell/IconCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React from 'react';
import { type IconDefinition } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import { useDeprecationWarning } from 'src/utils';

import './IconCell.scss';

export type IconCellProps = {
Expand All @@ -12,6 +14,8 @@ export type IconCellProps = {
function IconCell({
icon,
}: IconCellProps) {
useDeprecationWarning({ componentName: 'IconCell' });

return (
<div className="IconCell">
<FontAwesomeIcon icon={icon} />
Expand Down
2 changes: 1 addition & 1 deletion src/Main/Main.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Main from './Main';
import mdx from './Main.mdx';

export default {
title: 'Layouts/Main',
title: 'Components/Main',
component: Main,
parameters: {
docs: {
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useDeprecationWarning';
21 changes: 21 additions & 0 deletions src/utils/useDeprecationWarning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useEffect } from 'react';

type useDeprecationWarningProps = {
componentName: string,
message?: string,
}

export function useDeprecationWarning({
componentName,
message = '',
} : useDeprecationWarningProps) {
useEffect(() => {
const warningMessage = `Warning: ${componentName} is deprecated and will be removed in a future release.${
message ? ` ${message}` : ''}`;

if (process.env.NODE_ENV === 'development') {
// eslint-disable-next-line no-console
console.warn(warningMessage);
}
}, [componentName, message]);
}
Loading