Skip to content

Commit

Permalink
[@graphiql/react]: replace compose.ts with clsx for class concate…
Browse files Browse the repository at this point in the history
…nation (#2932)

* check interpolation

* add changeset

* ignore clsx word
  • Loading branch information
dimaMachina authored Dec 8, 2022
1 parent 106c197 commit 11e6ad1
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-camels-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphiql/react': patch
---

replace `compose.ts` with `clsx` for class concatenation
1 change: 1 addition & 0 deletions custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ codesandbox
combobox
commitlint
cosmicconfig
clsx
dompurify
dustjs
dset
Expand Down
1 change: 1 addition & 0 deletions packages/graphiql-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@reach/menu-button": "^0.17.0",
"@reach/tooltip": "^0.17.0",
"@reach/visually-hidden": "^0.17.0",
"clsx": "^1.2.1",
"codemirror": "^5.65.3",
"codemirror-graphql": "^2.0.2",
"copy-to-clipboard": "^3.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect } from 'react';
import { clsx } from 'clsx';

import { useEditorContext } from '../context';
import { useHeaderEditor, UseHeaderEditorArgs } from '../header-editor';
Expand Down Expand Up @@ -29,6 +30,6 @@ export function HeaderEditor({ isHidden, ...hookArgs }: HeaderEditorProps) {
}, [headerEditor, isHidden]);

return (
<div className={`graphiql-editor${isHidden ? ' hidden' : ''}`} ref={ref} />
<div className={clsx('graphiql-editor', isHidden && 'hidden')} ref={ref} />
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect } from 'react';
import { clsx } from 'clsx';

import { useEditorContext } from '../context';
import { useVariableEditor, UseVariableEditorArgs } from '../variable-editor';
Expand Down Expand Up @@ -31,6 +32,6 @@ export function VariableEditor({ isHidden, ...hookArgs }: VariableEditorProps) {
}, [variableEditor, isHidden]);

return (
<div className={`graphiql-editor${isHidden ? ' hidden' : ''}`} ref={ref} />
<div className={clsx('graphiql-editor', isHidden && 'hidden')} ref={ref} />
);
}
3 changes: 2 additions & 1 deletion packages/graphiql-react/src/history/components.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { QueryStoreItem } from '@graphiql/toolkit';
import { Fragment, useEffect, useRef, useState } from 'react';
import { clsx } from 'clsx';

import { useEditorContext } from '../editor';
import { CloseIcon, PenIcon, StarFilledIcon, StarIcon } from '../icons';
Expand Down Expand Up @@ -66,7 +67,7 @@ export function HistoryItem(props: QueryHistoryItemProps) {
formatQuery(props.item.query);

return (
<li className={'graphiql-history-item' + (isEditable ? ' editable' : '')}>
<li className={clsx('graphiql-history-item', isEditable && 'editable')}>
{isEditable ? (
<>
<input
Expand Down
6 changes: 3 additions & 3 deletions packages/graphiql-react/src/toolbar/button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { forwardRef, useState } from 'react';
import { clsx } from 'clsx';
import { Tooltip, UnStyledButton } from '../ui';
import { compose } from '../utility/compose';

import './button.css';

Expand All @@ -19,9 +19,9 @@ export const ToolbarButton = forwardRef<
{...props}
ref={ref}
type="button"
className={compose(
className={clsx(
'graphiql-toolbar-button',
error ? 'error' : '',
error && 'error',
props.className,
)}
onClick={event => {
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql-react/src/toolbar/listbox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentProps, forwardRef, ReactNode } from 'react';
import { clsx } from 'clsx';
import { Listbox, Tooltip } from '../ui';
import { createComponentGroup } from '../utility/component-group';
import { compose } from '../utility/compose';

import './listbox.css';

Expand All @@ -19,7 +19,7 @@ const ToolbarListboxRoot = forwardRef<
<Listbox.Input
{...props}
ref={ref}
className={compose('graphiql-toolbar-listbox', props.className)}
className={clsx('graphiql-toolbar-listbox', props.className)}
aria-label={labelWithValue}
>
<Tooltip label={labelWithValue}>
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql-react/src/toolbar/menu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { forwardRef, ReactNode } from 'react';
import { clsx } from 'clsx';
import { Menu, Tooltip } from '../ui';
import { createComponentGroup } from '../utility/component-group';
import { compose } from '../utility/compose';

import './menu.css';

Expand All @@ -17,7 +17,7 @@ const ToolbarMenuRoot = forwardRef<
<Menu {...props} ref={ref}>
<Tooltip label={label}>
<Menu.Button
className={compose(
className={clsx(
'graphiql-un-styled graphiql-toolbar-menu',
props.className,
)}
Expand Down
3 changes: 2 additions & 1 deletion packages/graphiql-react/src/ui/button-group.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { forwardRef } from 'react';
import { clsx } from 'clsx';

import './button-group.css';

Expand All @@ -9,7 +10,7 @@ export const ButtonGroup = forwardRef<
<div
{...props}
ref={ref}
className={`graphiql-button-group ${props.className || ''}`.trim()}
className={clsx('graphiql-button-group', props.className)}
/>
));
ButtonGroup.displayName = 'ButtonGroup';
15 changes: 7 additions & 8 deletions packages/graphiql-react/src/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { forwardRef } from 'react';
import { compose } from '../utility/compose';
import { clsx } from 'clsx';

import './button.css';

Expand All @@ -10,7 +10,7 @@ export const UnStyledButton = forwardRef<
<button
{...props}
ref={ref}
className={compose('graphiql-un-styled', props.className)}
className={clsx('graphiql-un-styled', props.className)}
/>
));
UnStyledButton.displayName = 'UnStyledButton';
Expand All @@ -24,13 +24,12 @@ export const Button = forwardRef<
<button
{...props}
ref={ref}
className={compose(
className={clsx(
'graphiql-button',
props.state === 'success'
? 'graphiql-button-success'
: props.state === 'error'
? 'graphiql-button-error'
: '',
{
success: 'graphiql-button-success',
error: 'graphiql-button-error',
}[props.state!],
props.className,
)}
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql-react/src/ui/dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { clsx } from 'clsx';
import { Dialog as ReachDialog } from '@reach/dialog';
import { VisuallyHidden } from '@reach/visually-hidden';
import { ComponentProps, forwardRef } from 'react';
import { CloseIcon } from '../icons';
import { createComponentGroup } from '../utility/component-group';
import { compose } from '../utility/compose';
import { UnStyledButton } from './button';

import './dialog.css';
Expand All @@ -22,7 +22,7 @@ const DialogClose = forwardRef<
{...props}
ref={ref}
type="button"
className={compose('graphiql-dialog-close', props.className)}
className={clsx('graphiql-dialog-close', props.className)}
>
<VisuallyHidden>Close dialog</VisuallyHidden>
<CloseIcon />
Expand Down
6 changes: 3 additions & 3 deletions packages/graphiql-react/src/ui/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
MenuList,
} from '@reach/menu-button';
import { ComponentProps, forwardRef } from 'react';
import { clsx } from 'clsx';
import { createComponentGroup } from '../utility/component-group';
import { compose } from '../utility/compose';

import './dropdown.css';

Expand All @@ -24,7 +24,7 @@ const MenuButton = forwardRef<
<ReachMenuButton
{...props}
ref={ref}
className={compose('graphiql-un-styled', props.className)}
className={clsx('graphiql-un-styled', props.className)}
/>
));
MenuButton.displayName = 'MenuButton';
Expand All @@ -42,7 +42,7 @@ const ListboxButton = forwardRef<
<ReachListboxButton
{...props}
ref={ref}
className={compose('graphiql-un-styled', props.className)}
className={clsx('graphiql-un-styled', props.className)}
/>
));
ListboxButton.displayName = 'ListboxButton';
Expand Down
6 changes: 3 additions & 3 deletions packages/graphiql-react/src/ui/markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { forwardRef } from 'react';
import { clsx } from 'clsx';
import { markdown } from '../markdown';
import { compose } from '../utility/compose';

import './markdown.css';

Expand All @@ -17,9 +17,9 @@ export const MarkdownContent = forwardRef<
<div
{...props}
ref={ref}
className={compose(
className={clsx(
`graphiql-markdown-${type}`,
onlyShowFirstChild ? ' graphiql-markdown-preview' : '',
onlyShowFirstChild && 'graphiql-markdown-preview',
props.className,
)}
dangerouslySetInnerHTML={{ __html: markdown.render(children) }}
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql-react/src/ui/spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { forwardRef } from 'react';
import { compose } from '../utility/compose';
import { clsx } from 'clsx';

import './spinner.css';

Expand All @@ -8,7 +8,7 @@ export const Spinner = forwardRef<HTMLDivElement, JSX.IntrinsicElements['div']>(
<div
{...props}
ref={ref}
className={compose('graphiql-spinner', props.className)}
className={clsx('graphiql-spinner', props.className)}
/>
),
);
Expand Down
12 changes: 6 additions & 6 deletions packages/graphiql-react/src/ui/tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { forwardRef } from 'react';
import { clsx } from 'clsx';
import { CloseIcon } from '../icons';
import { createComponentGroup } from '../utility/component-group';
import { compose } from '../utility/compose';
import { UnStyledButton } from './button';
import { Tooltip } from './tooltip';

Expand All @@ -20,9 +20,9 @@ const TabRoot = forwardRef<
ref={ref}
role="tab"
aria-selected={isActive}
className={compose(
className={clsx(
'graphiql-tab',
isActive ? 'graphiql-tab-active' : '',
isActive && 'graphiql-tab-active',
props.className,
)}
>
Expand All @@ -39,7 +39,7 @@ const TabButton = forwardRef<
{...props}
ref={ref}
type="button"
className={compose('graphiql-tab-button', props.className)}
className={clsx('graphiql-tab-button', props.className)}
>
{props.children}
</UnStyledButton>
Expand All @@ -54,7 +54,7 @@ const TabClose = forwardRef<HTMLButtonElement, JSX.IntrinsicElements['button']>(
{...props}
ref={ref}
type="button"
className={compose('graphiql-tab-close', props.className)}
className={clsx('graphiql-tab-close', props.className)}
>
<CloseIcon />
</UnStyledButton>
Expand All @@ -74,7 +74,7 @@ export const Tabs = forwardRef<HTMLDivElement, JSX.IntrinsicElements['div']>(
{...props}
ref={ref}
role="tablist"
className={compose('graphiql-tabs', props.className)}
className={clsx('graphiql-tabs', props.className)}
>
{props.children}
</div>
Expand Down
9 changes: 0 additions & 9 deletions packages/graphiql-react/src/utility/compose.ts

This file was deleted.

5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8043,6 +8043,11 @@ clone@^2.1.1:
resolved "https://registry.yarnpkg.com/clone/-/clone-2.1.2.tgz#1b7f4b9f591f1e8f83670401600345a02887435f"
integrity sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==

clsx@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.2.1.tgz#0ddc4a20a549b59c93a4116bb26f5294ca17dc12"
integrity sha512-EcR6r5a8bj6pu3ycsa/E/cKVGuTgZJZdsyUYHOksG/UHIiKfjxzRxYJpyVBwYaQeOvghal9fcc4PidlgzugAQg==

co@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
Expand Down

0 comments on commit 11e6ad1

Please sign in to comment.