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

fix(ui): State CSS classes #620

Merged
merged 6 commits into from
Sep 13, 2023
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
2 changes: 2 additions & 0 deletions build/api/ui.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ export interface ButtonListProps extends ComponentClassNameProps, DeprecatedButt

// @public (undocumented)
export interface ButtonOwnProps extends DeprecatedButtonOwnProps, ComponentClassNameProps {
// (undocumented)
accent?: false | 'strong' | 'theme';
// (undocumented)
active?: boolean;
// (undocumented)
Expand Down
205 changes: 101 additions & 104 deletions packages/admin-sandbox/admin/pages/buttons.tsx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/admin-sandbox/admin/pages/fieldContainers.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, ButtonGroup, Divider, FieldContainer, Label, Stack, TextInput } from '@contember/ui'
import { AlignCenterHorizontalIcon, AlignCenterVerticalIcon, AlignEndHorizontalIcon, AlignEndVerticalIcon, AlignStartHorizontalIcon, AlignStartVerticalIcon, ColumnsIcon, RowsIcon, StretchHorizontalIcon } from 'lucide-react'
import { AlignCenterVerticalIcon, AlignEndVerticalIcon, AlignStartVerticalIcon, ColumnsIcon, RowsIcon, StretchHorizontalIcon } from 'lucide-react'
import { useState } from 'react'
import { SlotSources } from '../components/Slots'

Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/components/Auto/AutoGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const createDataGridColumns = (
<GenericCell key="action" shrunk>
<Stack horizontal>
{createEditLinkTarget && (
<LinkButton to={createEditLinkTarget(entityName)} distinction="seamless" size="small">
<LinkButton accent="strong" to={createEditLinkTarget(entityName)} distinction="seamless" size="small">
edit
</LinkButton>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { EntityAccessor, useEntity, useMutationState } from '@contember/binding'
import { useColorScheme } from '@contember/react-utils'
import { Button, ButtonProps } from '@contember/ui'
import { colorSchemeClassName, controlsThemeClassName, listClassName } from '@contember/utilities'
import { Trash2Icon } from 'lucide-react'
import { ReactNode, memo, useCallback } from 'react'
import { usePersistWithFeedback } from '../../../ui'
Expand All @@ -24,22 +22,20 @@ export type DeleteEntityButtonProps =
* @group Action buttons
*/
export const DeleteEntityButton = memo((props: DeleteEntityButtonProps) => {
const { children, immediatePersist, className, ...rest } = props
const { children, immediatePersist, ...rest } = props
const parentEntity = useEntity()
const triggerPersist = usePersistWithFeedback()
const isMutating = useMutationState()
const onClick = useCallback(() => {
if (props.immediatePersist && !confirm('Really?')) {
if (immediatePersist && !confirm('Really?')) {
return
}
parentEntity.deleteEntity()

if (props.immediatePersist && triggerPersist) {
if (immediatePersist && triggerPersist) {
triggerPersist().catch(() => { })
}
}, [triggerPersist, props.immediatePersist, parentEntity])

const colorScheme = useColorScheme()
}, [triggerPersist, immediatePersist, parentEntity])

if (!(parentEntity instanceof EntityAccessor)) {
return null
Expand All @@ -48,15 +44,12 @@ export const DeleteEntityButton = memo((props: DeleteEntityButtonProps) => {
return (
<Button
square
accent="strong"
borderRadius="full"
distinction="seamless"
size="small"
{...rest}
className={listClassName([
controlsThemeClassName('danger', ':hover'),
colorSchemeClassName(colorScheme),
className,
])}
intent="danger"
disabled={isMutating || rest.disabled}
onClick={onClick}
>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/ui/src/components/ActionableBox/ActionableBox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useClassNameFactory, useComposeRef } from '@contember/react-utils'
import { ComponentClassNameProps, flatClassNameList } from '@contember/utilities'
import { PencilIcon, Trash2Icon } from 'lucide-react'
import { MouseEvent as ReactMouseEvent, ReactNode, memo, useCallback, useMemo, useRef, useState } from 'react'
import { MouseEvent as ReactMouseEvent, ReactNode, memo, useMemo, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import { HTMLDivElementProps } from '../../types'
import { Box, BoxOwnProps } from '../Box'
Expand Down
314 changes: 204 additions & 110 deletions packages/ui/src/components/Forms/Button/Button.css

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions packages/ui/src/components/Forms/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ColorSchemeContext, useClassNameFactory, useColorScheme } from '@contember/react-utils'
import { colorSchemeClassName, contentThemeClassName, controlsThemeClassName, dataAttribute, deprecate, fallback } from '@contember/utilities'
import { colorSchemeClassName, controlsThemeClassName, dataAttribute, deprecate, fallback, isDefined } from '@contember/utilities'
import { createElement, forwardRef, memo } from 'react'
import type { HTMLButtonElementProps } from '../../../types'
import { Spinner } from '../../Spinner/Spinner'
import { Text } from '../../Typography'
import { AnchorButtonProps, BaseButtonProps, ButtonProps } from './Types'
Expand Down Expand Up @@ -89,6 +88,7 @@ Button.displayName = 'Interface.Button'

export const BaseButton = memo(forwardRef<any, BaseButtonProps>(({
Component,
accent = 'theme',
active,
align,
bland,
Expand Down Expand Up @@ -130,7 +130,7 @@ export const BaseButton = memo(forwardRef<any, BaseButtonProps>(({
padding = fallback(padding, flow === 'generous' || flow === 'generousBlock', 'padding')

deprecate('1.3.0', typeof elevated !== 'boolean', '`elevate` prop', '`elevate` prop')
elevated = fallback(elevated, typeof elevation !== 'boolean', elevation === 'default' ? true : false)
elevated = fallback(elevated, elevation === 'default', true)

deprecate('1.3.0', justification !== undefined, '`justification` prop', '`justify` prop')
justify = fallback(justify, justification !== undefined, ({ default: 'center', justifyStart: 'start', justifyCenter: 'center', justifyEnd: 'end' } as const)[justification ?? 'default'])
Expand All @@ -146,17 +146,16 @@ export const BaseButton = memo(forwardRef<any, BaseButtonProps>(({
rest['tabIndex'] = -1
}

const themeIntent = !disabled ? intent : 'default'
const className = useClassNameFactory(componentClassName)
const colorScheme = useColorScheme()
const scheme = schemeProp ?? colorScheme

return createElement(Component, {
...rest,
'data-accent': dataAttribute(accent),
'data-active': dataAttribute(active),
'data-align': dataAttribute(align),
// TODO: deprecated since v1.3.0
'data-bland': dataAttribute(bland),
'data-bland': dataAttribute(bland), // TODO: deprecated since v1.3.0
'data-border-radius': dataAttribute(borderRadius),
'data-disabled': dataAttribute(disabled),
'data-display': dataAttribute(display),
Expand All @@ -172,8 +171,7 @@ export const BaseButton = memo(forwardRef<any, BaseButtonProps>(({
'data-square': dataAttribute(square),
disabled,
'className': className(null, [
contentThemeClassName(distinction === 'default' ? null : themeIntent),
controlsThemeClassName(themeIntent),
controlsThemeClassName(intent),
colorSchemeClassName(scheme),
classNameProp,
]),
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/components/Forms/Button/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface AnchorBasedProps extends Omit<HTMLAnchorElementProps, 'ref' | '
}

export interface ButtonOwnProps extends DeprecatedButtonOwnProps, ComponentClassNameProps {
accent?: false | 'strong' | 'theme'
active?: boolean
align?: 'start' | 'center' | 'end' | 'stretch'
borderRadius?: Exclude<StackOwnProps['gap'], 'large' | 'larger'> | 'full'
Expand Down Expand Up @@ -88,7 +89,7 @@ export type ButtonGroupOrientation = Default | 'horizontal' | 'vertical'
export type DeprecatedButtonDefault = Default
/** @deprecated No alternative */
export interface DeprecatedButtonOwnProps {
/** @deprecated Use `distinction` instead to suppress button visuals */
/** @deprecated Use `distinction`, `theme` or `accent={false}` props instead to suppress button visuals */
bland?: boolean
/** @deprecated Use `elevated` instead */
elevation?: ButtonElevation
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/src/components/Typography/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useClassName } from '@contember/react-utils'
import { ComponentClassNameProps, PolymorphicComponent, assert } from '@contember/utilities'
import { ComponentClassNameProps, PolymorphicComponent } from '@contember/utilities'
import { ReactNode, forwardRef, memo } from 'react'
import { HTMLSpanElementProps } from '../../types'

export interface TextOwnProps<Translate extends Function = Function> extends ComponentClassNameProps {
children?: ReactNode
Expand Down
Loading