Skip to content

Commit

Permalink
UI: move from cx to cn classname utility
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Feb 6, 2024
1 parent 94912a3 commit 2ec263f
Show file tree
Hide file tree
Showing 52 changed files with 773 additions and 746 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from 'react';

import type { ActionListItemDescriptor } from '../../../../types/actionlist';
import { Color } from '../../../../types/icon';
import { cn } from '../../../../utils';
import { handleMouseUpByBlurring } from '../../../../utils/focus';
import { Box } from '../../../Box';
import { UnstyledLink } from '../../../Button/BaseLink';
import { Icon } from '../../../Icon';
import { Text } from '../../../Text';
import styles from '../../ActionList.module.scss';
import cx from 'classnames';
import React from 'react';

export type ItemProps = ActionListItemDescriptor;

Expand All @@ -28,7 +29,7 @@ export function Item({
active,
role,
}: ItemProps) {
const className = cx(
const className = cn(
styles.Item,
disabled && styles.disabled,
destructive && styles.destructive,
Expand Down Expand Up @@ -65,7 +66,7 @@ export function Item({
);

const suffixMarkup = suffix && (
<span className={cx(styles.Suffix, styles.Prefix)}>
<span className={cn(styles.Suffix, styles.Prefix)}>
{<Icon source={suffix} color={color} />}
</span>
);
Expand Down
11 changes: 6 additions & 5 deletions packages/opub-ui/src/components/AlertDialog/AlertDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import styles from '../Dialog/Dialog.module.scss';
import React, { forwardRef, Ref } from 'react';
import * as AlertDialogRadix from '@radix-ui/react-alert-dialog';

import { cn } from '../../utils';
import { Footer, FooterProps } from '../Dialog/components';
import styles from '../Dialog/Dialog.module.scss';
import { Header } from './components';
import * as AlertDialogRadix from '@radix-ui/react-alert-dialog';
import cx from 'classnames';
import React, { forwardRef, Ref } from 'react';

interface DialogProps extends AlertDialogRadix.DialogProps {
Trigger?: AlertDialogRadix.DialogTriggerProps;
Expand Down Expand Up @@ -74,7 +75,7 @@ const Content = forwardRef((props: ContentProps, ref: any) => {
const rId = React.useId();
const finalId = id || rId;

const classname = cx(
const classname = cn(
styles.Dialog,
small && styles.sizeSmall,
large && styles.sizeLarge,
Expand Down
8 changes: 4 additions & 4 deletions packages/opub-ui/src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Box } from '../Box';
import * as AvatarRadix from '@radix-ui/react-avatar';

import { cn } from '../../utils';
import { Text } from '../Text';
import styles from './Avatar.module.scss';
import * as AvatarRadix from '@radix-ui/react-avatar';
import cx from 'classnames';

type Props = {
showLabel?: boolean;
Expand Down Expand Up @@ -38,7 +38,7 @@ const Avatar = ({
.map((item: any) => item[0])
.join('')
.toUpperCase();
const className = cx(
const className = cn(
styles.Avatar,
variantStyles[size],
size === 'medium' && showInitials && styles.AvatarProfileMedium,
Expand Down
4 changes: 2 additions & 2 deletions packages/opub-ui/src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BadgeProps } from '../../types/badge';
import { cn } from '../../utils';
import { Text } from '../Text';
import styles from './Badge.module.scss';
import { Pip } from './components/Pip';
import cx from 'classnames';

export const Badge = ({
progress = 'default',
Expand Down Expand Up @@ -33,7 +33,7 @@ export const Badge = ({
return `${name}${value.charAt(0).toUpperCase()}${value.slice(1)}`;
}

const className = cx(
const className = cn(
styles.Badge,
status && styles[variationName('status', status)]
);
Expand Down
4 changes: 2 additions & 2 deletions packages/opub-ui/src/components/Badge/components/Pip/Pip.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cx from 'classnames';
import { Progress, Status } from '../../../../types/badge';
import { cn } from '../../../../utils';
import { Text } from '../../../Text';
import styles from './Pip.module.scss';

Expand All @@ -18,7 +18,7 @@ export const Pip = ({
progress = 'complete',
accessibilityLabelOverride,
}: PipProps) => {
const className = cx(
const className = cn(
styles.Pip,
status && styles[variationName('status', status)],
progress && styles[variationName('progress', progress)]
Expand Down
10 changes: 7 additions & 3 deletions packages/opub-ui/src/components/Box/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import cx from 'classnames';
import React, { createElement, forwardRef } from 'react';

import { BoxProps, FlexStyleProps } from '../../types/box';
import { getResponsiveProps, sanitizeCustomProperties } from '../../utils/css';
import {
cn,
getResponsiveProps,
sanitizeCustomProperties,
} from '../../utils/css';
import boxStyles from './Box.module.scss';

export const Box = forwardRef<HTMLElement, BoxProps & FlexStyleProps>(
Expand Down Expand Up @@ -175,7 +179,7 @@ export const Box = forwardRef<HTMLElement, BoxProps & FlexStyleProps>(
alignContent,
} as React.CSSProperties;

const className = cx(
const className = cn(
boxStyles.Box,
visuallyHidden && boxStyles.visuallyHidden,
printHidden && boxStyles.printHidden,
Expand Down
7 changes: 4 additions & 3 deletions packages/opub-ui/src/components/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';

import { cn } from '../../utils';
import { Text } from '../Text';
import styles from './Breadcrumbs.module.scss';
import cx from 'classnames';
import React from 'react';

type Props = {
crumbs: {
Expand All @@ -12,7 +13,7 @@ type Props = {
itemsAfterCollapse?: number;
};

const className = cx(styles.Breadcrumbs);
const className = cn(styles.Breadcrumbs);

const Breadcrumbs = ({
crumbs,
Expand Down
13 changes: 6 additions & 7 deletions packages/opub-ui/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import {
IconChevronUp,
IconSelector,
} from '@tabler/icons-react';
import cx from 'classnames';

import { ConnectedDisclosure } from '../../types/button';
import { variationName } from '../../utils/css';
import { cn, variationName } from '../../utils/css';
import { handleMouseUpByBlurring, MouseUpBlurHandler } from '../../utils/focus';
import { Icon } from '../Icon';
import { Menu } from '../Menu';
Expand Down Expand Up @@ -127,7 +126,7 @@ const Button = React.forwardRef(
} = props;
const isDisabled = disabled || loading;

const className = cx(
const className = cn(
styles.Button,
styles[variationName('kind', kind)],
styles[variationName('variant', variant)],
Expand All @@ -146,7 +145,7 @@ const Button = React.forwardRef(

const childMarkup = children ? (
<span
className={cx(styles.Text, removeUnderline && styles.removeUnderline)}
className={cn(styles.Text, removeUnderline && styles.removeUnderline)}
// Fixes Safari bug that doesn't re-render button text to correct color
key={disabled ? 'text-disabled' : 'text'}
>
Expand All @@ -165,12 +164,12 @@ const Button = React.forwardRef(
) : null;

const iconMarkup = icon ? (
<span className={cx(styles.Icon, loading && styles.hidden)}>{icon}</span>
<span className={cn(styles.Icon, loading && styles.hidden)}>{icon}</span>
) : null;

const disclosureMarkup = disclosure ? (
<span className={styles.Icon}>
<div className={cx(styles.DisclosureIcon, loading && styles.hidden)}>
<div className={cn(styles.DisclosureIcon, loading && styles.hidden)}>
{loading ? (
<div className={styles.Placeholder} />
) : (
Expand All @@ -187,7 +186,7 @@ const Button = React.forwardRef(

let connectedDisclosureMarkup;
if (connectedDisclosure && connectedDisclosure.actions.length > 0) {
const connectedDisclosureClassName = cx(
const connectedDisclosureClassName = cn(
styles.Button,
styles[variationName('kind', kind)],
styles[variationName('variant', variant)],
Expand Down
6 changes: 3 additions & 3 deletions packages/opub-ui/src/components/ButtonGroup/ButtonGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cx from 'classnames';
import React from 'react';
import { elementChildren } from '../../utils';

import { cn, elementChildren } from '../../utils';
import styles from './ButtonGroup.module.scss';
import { Item } from './components';

Expand Down Expand Up @@ -29,7 +29,7 @@ export function ButtonGroup({
connectedTop,
noWrap,
}: ButtonGroupProps) {
const className = cx(
const className = cn(
styles.ButtonGroup,
spacing && styles[spacing],
segmented && styles.segmented,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import cx from 'classnames';
import React from 'react';
import { useToggle } from '../../../../utils';

import { cn, useToggle } from '../../../../utils';
import styles from '../../ButtonGroup.module.scss';

export interface ItemProps {
Expand All @@ -14,7 +14,7 @@ export function Item({ button }: ItemProps) {
setFalse: forceFalseFocused,
} = useToggle(false);

const className = cx(
const className = cn(
styles.Item,
focused && styles['Item-focused'],
button.props.plain && styles['Item-plain']
Expand Down
15 changes: 8 additions & 7 deletions packages/opub-ui/src/components/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
'use client';

import { Icon } from '../Icon';
import { Text } from '../Text';
import styles from './Calendar.module.scss';
import { CalendarGrid } from './components/CalendarGrid';
import { forwardRef, LegacyRef } from 'react';
import { GregorianCalendar } from '@internationalized/date';
import { AriaCalendarProps, DateValue } from '@react-types/calendar';
import { IconArrowLeft, IconArrowRight } from '@tabler/icons-react';
import cx from 'classnames';
import { forwardRef, LegacyRef } from 'react';
import { useCalendar, useLocale } from 'react-aria';
import { CalendarStateOptions, useCalendarState } from 'react-stately';

import { cn } from '../../utils';
import { Icon } from '../Icon';
import { Text } from '../Text';
import styles from './Calendar.module.scss';
import { CalendarGrid } from './components/CalendarGrid';

function createCalendar(identifier: any) {
switch (identifier) {
case 'gregory':
Expand Down Expand Up @@ -48,7 +49,7 @@ const Calendar = forwardRef(
...othersNext
} = nextButtonProps;

const themeClass = cx(styles.Calendar, {});
const themeClass = cn(styles.Calendar);
return (
<div
{...calendarProps}
Expand Down
15 changes: 8 additions & 7 deletions packages/opub-ui/src/components/Calendar/RangeCalendar.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
'use client';

import { Icon } from '../Icon';
import { Text } from '../Text';
import styles from './Calendar.module.scss';
import { CalendarGrid } from './components/CalendarGrid';
import React from 'react';
import { GregorianCalendar } from '@internationalized/date';
import { AriaRangeCalendarProps, DateValue } from '@react-types/calendar';
import { IconArrowLeft, IconArrowRight } from '@tabler/icons-react';
import cx from 'classnames';
import React from 'react';
import { useLocale, useRangeCalendar } from 'react-aria';
import {
RangeCalendarStateOptions,
useRangeCalendarState,
} from 'react-stately';

import { cn } from '../../utils';
import { Icon } from '../Icon';
import { Text } from '../Text';
import styles from './Calendar.module.scss';
import { CalendarGrid } from './components/CalendarGrid';

function createCalendar(identifier: any) {
switch (identifier) {
case 'gregory':
Expand All @@ -35,7 +36,7 @@ function RangeCalendar(props: Props) {
});

let ref = React.useRef(null);
const themeClass = cx(styles.Calendar, {});
const themeClass = cn(styles.Calendar);

let { calendarProps, prevButtonProps, nextButtonProps, title } =
useRangeCalendar(props, state, ref);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { CalendarDate, isSameDay, isToday } from '@internationalized/date';
import { Text } from '../../../Text';
import cx from 'classnames';
import React from 'react';
import { CalendarDate, isSameDay, isToday } from '@internationalized/date';
import { AriaCalendarCellProps, useCalendarCell } from 'react-aria';
import { CalendarState, RangeCalendarState } from 'react-stately';

import { cn } from '../../../../utils';
import { Text } from '../../../Text';
import styles from '../../Calendar.module.scss';

interface CalendarCellProps extends AriaCalendarCellProps {
Expand All @@ -30,7 +31,7 @@ export function CalendarCell({ state, date }: CalendarCellProps) {
let isSelectionEnd =
isSelected && highlightedRange && isSameDay(date, highlightedRange.end);

const classname = cx(
const classname = cn(
styles.Cell,
isToday(date, state.timeZone) && styles.Today,
isSelected && styles.Selected,
Expand Down
11 changes: 6 additions & 5 deletions packages/opub-ui/src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { forwardRef } from 'react';
import * as CheckboxRadix from '@radix-ui/react-checkbox';
import { IconCheck, IconMinus } from '@tabler/icons-react';

import { CheckboxProps } from '../../types/checkbox';
import { cn } from '../../utils';
import { Choice } from '../Choice';
import { Icon } from '../Icon';
import styles from './Checkbox.module.scss';
import * as CheckboxRadix from '@radix-ui/react-checkbox';
import { IconCheck, IconMinus } from '@tabler/icons-react';
import cx from 'classnames';
import React, { forwardRef } from 'react';

const Checkbox = forwardRef(
(
Expand All @@ -17,7 +18,7 @@ const Checkbox = forwardRef(
const id = React.useId();
const isIndeterminate = props.checked === 'indeterminate';

const inputClassName = cx(
const inputClassName = cn(
styles.Input,
error && styles.Error,
props.disabled && styles.Disabled
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useId } from 'react';

import { CheckboxGroupProps } from '../../types/choicelist';
import { cn } from '../../utils';
import { Checkbox } from '../Checkbox';
import { InlineMessage } from '../InlineMessage';
import { Text } from '../Text';
import styles from './CheckboxGroup.module.scss';
import cx from 'classnames';
import React, { useId } from 'react';

export const CheckboxGroup = React.forwardRef(
(
Expand Down Expand Up @@ -51,7 +52,7 @@ export const CheckboxGroup = React.forwardRef(
onChange && onChange(nextArr, nameProp);
}

const wrapperClassName = cx(styles.CheckboxGroup);
const wrapperClassName = cn(styles.CheckboxGroup);
const titleMarkup = title ? (
<Text variant="bodyMd" as="legend" visuallyHidden={titleHidden}>
{title}
Expand Down
Loading

0 comments on commit 2ec263f

Please sign in to comment.