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

Fixes20240726 canary #24

Merged
merged 17 commits into from
Jul 26, 2024
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
10 changes: 3 additions & 7 deletions lib/badges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ export const Badge = forwardRef(
component="span"
padding="2"
paddingInline="3"
fontSize="0"
fontWeight="medium"
className={[className, variant && badgePurposeClassNames[variant]]}
{...props}
>
{isStringLike(children) ? (
<Box
component="span"
fontSize="0"
fontWeight="medium"
textOverflow="ellipsis"
textAlign="center"
>
<Box component="span" textOverflow="ellipsis" textAlign="center">
{children}
</Box>
) : (
Expand Down
14 changes: 14 additions & 0 deletions lib/box.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ export const textOverflowVariants = styleVariants(
(value) => [textOverflowBase, value],
);

export type TextWrap = 'pretty' | 'balance' | 'nowrap';

export const textWrapVariants = styleVariants({
balance: {
textWrap: 'balance',
},
pretty: {
textWrap: 'pretty',
},
nowrap: {
textWrap: 'nowrap',
},
} satisfies Record<TextWrap, StyleRule>);

export type FlexDirection = 'row' | 'column';

export const flexDirectionVariants = styleVariants(
Expand Down
6 changes: 4 additions & 2 deletions lib/box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
flexShrinkClass,
flexWrapVariants,
type Wrap,
textWrapVariants,
type TextWrap,
} from './box.css.js';
import { isNotFalsy, matchViewportVariants } from './component-utils.js';
import { TooltipLazy } from './tooltip-lazy.js';
Expand All @@ -57,7 +59,6 @@ import {
type FontSize,
type FontWeight,
type LineHeight,
type TextWrap,
} from './typography.css.js';

export type BoxProps<T extends keyof ReactHTMLElementsHacked = 'div'> = Merge<
Expand Down Expand Up @@ -85,12 +86,12 @@ export type BoxProps<T extends keyof ReactHTMLElementsHacked = 'div'> = Merge<

textAlign?: TextAlign | Falsy;
textOverflow?: TextOverflow | Falsy;
textWrap?: TextWrap | Falsy;

fontSize?: FontSize | Falsy;
capSize?: FontSize | Falsy;
fontWeight?: FontWeight | Falsy;
lineHeight?: LineHeight | Falsy;
textWrap?: TextWrap | Falsy;

overflow?: Overflow | Falsy;

Expand Down Expand Up @@ -256,6 +257,7 @@ export const Box = forwardRef(
),

textAlign && textAlignVariants[textAlign],
textWrap && textWrapVariants[textWrap],

isNotFalsy(rounded) && roundedVariants[rounded],

Expand Down
15 changes: 11 additions & 4 deletions lib/button.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export const buttonClassName = style([
userSelect: 'none',
borderRadius: baseVars.border.radius,
borderWidth: baseVars.border.width,
transitionProperty: 'background-color, color, border-color',
transitionDuration: '0.08s',
transitionTimingFunction: 'ease-in-out',
selectors: {
'&[disabled]': {
pointerEvents: 'none',
Expand Down Expand Up @@ -118,14 +121,18 @@ export const iconClassName = style({
width: '0.7em', // hack, this should be variable based on the font-size
});

export const visiblyHiddenClass = style({
visibility: 'hidden',
});

export const busyButtonClass = style({
pointerEvents: 'none',
});

export const busySpinnerClass = style({
position: 'absolute',
});

export const inlineBleedClass = style({
marginBlock: calc(propsVars.space[0]).negate().toString(),
});

export const visiblyHiddenClass = style({
visibility: 'hidden',
});
2 changes: 1 addition & 1 deletion lib/button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Button', () => {
// ASSERT
expect(screen.getByRole('button')).toMatchInlineSnapshot(`
<button
class="button_buttonVariantClassNames_default__1sytq441 button_buttonClassName__1sytq44p layout_alignItemsVariants_center__17vpgba1 layout_justifyContentVariants_center__17vpgbad box_viewportStyleVariants_2__fg8qdbmn box_flexWrapVariants_nowrap__fg8qdbm0 box_viewportStyleVariants_5__fg8qdben box_viewportStyleVariants_6__fg8qdbc1 box_flexDirectionVariants_row__fg8qdblt"
class="button_buttonVariantClassNames_default__1sytq441 button_buttonClassName__1sytq44p layout_alignItemsVariants_center__17vpgba1 layout_justifyContentVariants_center__17vpgbad box_viewportStyleVariants_2__fg8qdbmq box_flexWrapVariants_nowrap__fg8qdbm3 box_viewportStyleVariants_5__fg8qdben box_viewportStyleVariants_6__fg8qdbc1 box_flexDirectionVariants_row__fg8qdblw"
type="button"
>
<span
Expand Down
31 changes: 15 additions & 16 deletions lib/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
iconClassName,
inlineBleedClass,
visiblyHiddenClass,
busySpinnerClass,
} from './button.css.js';
import { differentOriginLinkProps } from './component-utils.js';
import { useStringLikeDetector } from './hooks/use-string-like.js';
Expand Down Expand Up @@ -68,17 +69,13 @@ export type ButtonIconProps<
}
>;

/** @private */
const IconBox: FC<{
icon: ReactElement | FC;
busy?: boolean | Falsy;
capSize?: FontSize;
}> = ({ icon, busy, ...props }) => (
<Box
{...props}
component="span"
className={[iconClassName, busy && visiblyHiddenClass]}
>
const IconBox: FC<
BoxProps<'span'> & {
icon: ReactElement | FC;
capSize?: FontSize;
}
> = ({ icon, className, ...props }) => (
<Box {...props} component="span" className={[className, iconClassName]}>
{isValidElement<ReactElementDefaultPropsType>(icon)
? icon
: icon({} /* { className: iconClassName } */)}
Expand Down Expand Up @@ -199,10 +196,10 @@ export const Button = forwardRef(
]}
>
{iconStart && (
<IconBox capSize={fontSize} busy={busy} icon={iconStart} />
<IconBox capSize={fontSize} icon={iconStart} {...busyAttributes} />
)}

{!busy && hasStringChildren && (
{hasStringChildren && (
<ExactText
component="span"
textAlign={textAlign}
Expand All @@ -213,15 +210,17 @@ export const Button = forwardRef(
</ExactText>
)}

{!busy && children && !hasStringChildren && (
{!hasStringChildren && children && (
<Box flexGrow component="span" {...busyAttributes}>
{children}
</Box>
)}

{busy && <Spinner capSize={fontSize} />}
{busy && <Spinner className={busySpinnerClass} capSize={fontSize} />}

{iconEnd && <IconBox capSize={fontSize} busy={busy} icon={iconEnd} />}
{iconEnd && (
<IconBox capSize={fontSize} icon={iconEnd} {...busyAttributes} />
)}
</UnstyledButton>
);
},
Expand Down
8 changes: 4 additions & 4 deletions lib/callout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import {
PositiveIcon,
} from './icons.js';
import type { PurposeVariant } from './purpose.css.js';
import type { Merge, ReactHTMLElementsHacked } from './types.js';
import type { Falsy, Merge, ReactHTMLElementsHacked } from './types.js';
import { ExactText } from './typography.js';
import { isValidElementOfType } from './utils.js';

export type { PurposeVariant as CalloutVariant };

function variantIcon(variant: PurposeVariant): ReactNode {
function variantIcon(variant: PurposeVariant | Falsy): ReactNode {
const props = { className: iconClassName };

switch (variant) {
Expand All @@ -41,7 +41,7 @@ export type CalloutCommonProps = {
align?: never;
children: ReactNode;
icon?: ReactNode;
variant?: PurposeVariant;
variant?: PurposeVariant | Falsy;
};

export type CalloutProps<T extends keyof ReactHTMLElementsHacked = 'div'> =
Expand Down Expand Up @@ -70,7 +70,7 @@ export const Callout = ({
return (
<Box
space={space}
className={[className, calloutStyleVariants[variant]]}
className={[className, variant && calloutStyleVariants[variant]]}
role="alert"
aria-live="polite"
{...props}
Expand Down
4 changes: 3 additions & 1 deletion lib/forms.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export const formInputOuterClassName = style({
export const formInputInnerClassName = style([
{
selectors: {
'&::placeholder': {},
'&::placeholder': {
color: baseVars.color.muted.fgColor,
},
},
},
]);
Expand Down
10 changes: 9 additions & 1 deletion lib/forms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export const FormInput = forwardRef<HTMLInputElement, FormInputProps>(
message,
autoFocus,
customValidity,
flexGrow,
hidden,
...props
},
forwardedRef,
Expand All @@ -146,7 +148,12 @@ export const FormInput = forwardRef<HTMLInputElement, FormInputProps>(
const ref = useCombinedRefs(forwardedRef, ourRef);

return (
<Block className={className} space={defaultFormInputSpace}>
<Block
flexGrow={flexGrow}
className={className}
space={defaultFormInputSpace}
hidden={hidden}
>
{label && (
<FormInputLabel
htmlFor={!inputTypeProps.readOnly ? id : undefined}
Expand All @@ -169,6 +176,7 @@ export const FormInput = forwardRef<HTMLInputElement, FormInputProps>(
{...inputTypeProps}
autoFocus={definitelyAutoFocus}
id={id}
flexGrow={flexGrow}
/>
{message && <FormInputMessage message={message} />}
</Block>
Expand Down
4 changes: 2 additions & 2 deletions lib/loaders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type SpinnerProps = Merge<
>;

export const Spinner: FC<SpinnerProps> = ({
size = '1',
size,
className,
inline = true,
delay = false,
Expand All @@ -39,7 +39,7 @@ export const Spinner: FC<SpinnerProps> = ({
? spinnerAnimationVariantClassNames.delay
: spinnerAnimationVariantClassNames.normal,
inline && inlineSpinnerClass,
!inline && spinnerSizeVariantClassNames[size],
size && spinnerSizeVariantClassNames[size],
]}
{...props}
>
Expand Down
12 changes: 6 additions & 6 deletions lib/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,12 @@ export const buttonVariantTokens = {
},
danger: {
rest: {
bgColor: openPropsTokens.red5,
borderColor: openPropsTokens.red6,
fgColor: openPropsTokens.gray9,
bgColor: openPropsTokens.gray8,
borderColor: openPropsTokens.red10,
fgColor: openPropsTokens.red7,
},
hover: {
bgColor: openPropsTokens.red4,
bgColor: openPropsTokens.red9,
borderColor: openPropsTokens.red7,
fgColor: openPropsTokens.gray1,
},
Expand All @@ -373,9 +373,9 @@ export const buttonVariantTokens = {
fgColor: openPropsTokens.gray1,
},
disabled: {
bgColor: openPropsTokens.gray6,
bgColor: openPropsTokens.gray8,
borderColor: openPropsTokens.gray1,
fgColor: openPropsTokens.gray9,
fgColor: openPropsTokens.gray6,
},
},
inactive: {
Expand Down
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type Merge<A, B> = Omit<A, keyof B> & B;
// export type Merge<A, B> = { [K in Exclude<keyof A, keyof B>]: A[K] } & B;

export type { ReactHTMLAttributesHacked } from './react-html-attributes.js';
export type { ReactHTMLElementsHacked } from './react-html-elements.js';
Expand Down
2 changes: 0 additions & 2 deletions lib/typography.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ export type FontWeight = 'light' | 'normal' | 'medium' | 'semibold' | 'bold';

export type LineHeight = 'normal' | 'paragraph' | 'heading';

export type TextWrap = 'pretty' | 'balance' | 'nowrap';

const capSizeShape = {
fontSize: '',
lineHeight: '',
Expand Down
5 changes: 2 additions & 3 deletions lib/typography.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import {
type FontSize,
type FontWeight,
type LineHeight,
type TextWrap,
} from './typography.css.js';

export type HeadingLevel = '1' | '2' | '3' | '4' | '5' | '6';

export type { FontSize, FontWeight, LineHeight, TextWrap };
export type { FontSize, FontWeight, LineHeight };

export type CommonTextProps = {
secondary?: true | Falsy;
Expand All @@ -26,7 +25,7 @@ export type ParagraphProps<T extends keyof ReactHTMLElementsHacked = 'p'> =
Merge<BoxProps<T>, CommonTextProps>;

export type ExactTextProps<T extends keyof ReactHTMLElementsHacked = 'p'> =
Merge<BoxProps<T>, CommonTextProps>;
Merge<BoxProps<T>, CommonTextProps> & { fontSize?: never };

export type HeadingProps<T extends keyof ReactHTMLElementsHacked = 'p'> = Merge<
BoxProps<T>,
Expand Down
Loading