Skip to content

Commit

Permalink
Merge branch 'master' into ellipsis
Browse files Browse the repository at this point in the history
  • Loading branch information
ghsteff committed Aug 13, 2024
2 parents 93d96eb + d128652 commit 5ac8f22
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 44 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# 8.4.7 - 8/12/24
- [fix] Fix ref for textarea

# 8.4.6 - 8/9/24
- [improvement] Move Backdrop to TW theme #253

# 8.4.5 - 8/9/24
- [fix] Add "use client" for ThemeProvider #252

# 8.4.4 - 7/30/24
- [improvement] Added format of the date displayed in the calendar header
-
# 8.4.3 - 7/25/24
- [improvement] allow wildcards on theme hook

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@

- [Reaflow](https://reaflow.dev?utm=reablocks) - Open-source library for workflow and diagram graphs.
- [Reagraph](https://reagraph.dev?utm=reablocks) - Open-source library for large webgl based network graphs.
- [Reaviz](https://reaviz.dev?utm=reablocks) - Open-source library for data visualizations for React.
- [Reaviz](https://reaviz.dev?utm=reablocks) - Open-source library for data visualizations for React.
- [Reachat](https://reachat.dev?utm=reablocks) - Open-source library for building LLM/Chat UIs for React.

## 🔭 Development

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reablocks",
"version": "8.4.3",
"version": "8.4.7",
"description": "Component library for React",
"scripts": {
"build": "npm run build:js && npm run build:styles && npm run rewrite:stories && npm run build:docs",
Expand Down
1 change: 1 addition & 0 deletions src/form/Calendar/Calendar.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export const Multiview = () => {
value={range}
onChange={val => setRange(val as [Date, Date])}
showDayOfWeek
headerDateFormat="MMMM yyyy"
/>
<Divider />
<Stack justifyContent="center">
Expand Down
11 changes: 10 additions & 1 deletion src/form/Calendar/CalendarRange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export interface CalendarRangeProps
*/
previousYearArrow?: React.ReactNode | string;

/**
* The format of the date displayed in the calendar header.
*/
headerDateFormat?: string;

/**
* Theme for the CalendarRange.
*/
Expand All @@ -67,6 +72,7 @@ export const CalendarRange: FC<CalendarRangeProps> = ({
onChange,
monthsToDisplay = 2,
direction = 'future',
headerDateFormat = 'MMMM',
theme: customTheme,
...rest
}) => {
Expand Down Expand Up @@ -164,7 +170,10 @@ export const CalendarRange: FC<CalendarRangeProps> = ({
<SmallHeading className={theme.title} disableMargins>
{displayMonths.map(i => (
<span key={addMonths(viewValue, showPast ? -i : i).toDateString()}>
{format(addMonths(viewValue, showPast ? -i : i), 'MMMM')}
{format(
addMonths(viewValue, showPast ? -i : i),
headerDateFormat
)}
</span>
))}
</SmallHeading>
Expand Down
14 changes: 13 additions & 1 deletion src/form/Textarea/Textarea.story.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { useRef } from 'react';
import { Stack } from '../../layout/Stack';
import { Textarea } from './Textarea';
import { Button } from '@/elements';

export default {
title: 'Components/Form/Textarea',
Expand Down Expand Up @@ -32,3 +33,14 @@ export const Sizes = () => (
<Textarea value="Large" size="large" />
</Stack>
);

export const OutsideFocus = () => {
const inputRef = useRef(null);

return (
<Stack direction="column">
<Button onClick={() => inputRef?.current.focus()}>Click to focus</Button>
<Textarea ref={inputRef} />
</Stack>
);
};
32 changes: 19 additions & 13 deletions src/form/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, {
FC,
import {
forwardRef,
RefObject,
useImperativeHandle,
useLayoutEffect,
useRef
} from 'react';
import TextareaAutosize, {
Expand Down Expand Up @@ -61,32 +61,37 @@ export interface TextAreaRef {
focus?: () => void;
}

export const Textarea: FC<TextareaProps & TextAreaRef> = forwardRef<
TextAreaRef,
TextareaProps
>(
export const Textarea = forwardRef<TextAreaRef, TextareaProps>(
(
{
fullWidth,
size = 'medium',
containerClassName,
className,
error,
autoFocus,
theme: customTheme,
...rest
},
ref
inputRef
) => {
const containerRef = useRef<HTMLDivElement | null>(null);
const inputRef = useRef<HTMLTextAreaElement | null>(null);
const textareaRef = useRef<HTMLTextAreaElement | null>(null);

useImperativeHandle(ref, () => ({
inputRef,
useImperativeHandle(inputRef, () => ({
textareaRef,
containerRef,
blur: () => inputRef.current?.blur(),
focus: () => inputRef.current?.focus()
blur: () => textareaRef.current?.blur(),
focus: () => textareaRef.current?.focus()
}));

useLayoutEffect(() => {
if (autoFocus) {
// Small timeout for page loading
requestAnimationFrame(() => textareaRef.current?.focus());
}
}, [autoFocus]);

const theme: TextareaTheme = useComponentTheme('textarea', customTheme);

return (
Expand All @@ -100,14 +105,15 @@ export const Textarea: FC<TextareaProps & TextAreaRef> = forwardRef<
ref={containerRef}
>
<TextareaAutosize
ref={inputRef}
ref={textareaRef}
className={twMerge(
theme.input,
fullWidth && theme.fullWidth,
rest.disabled && theme.disabled,
theme.sizes[size],
className
)}
autoFocus={autoFocus}
{...rest}
/>
</div>
Expand Down
10 changes: 0 additions & 10 deletions src/layers/Backdrop/Backdrop.module.css

This file was deleted.

35 changes: 23 additions & 12 deletions src/layers/Backdrop/Backdrop.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { FC, MouseEvent } from 'react';
import classNames from 'classnames';
import { motion } from 'framer-motion';
import css from './Backdrop.module.css';
import { cn, useComponentTheme } from '@/utils';

import { BackdropTheme } from './BackdropTheme';

export interface BackdropProps {
/**
Expand All @@ -19,6 +20,11 @@ export interface BackdropProps {
*/
className?: string;

/**
* Theme for the Backdrop.
*/
theme?: BackdropTheme;

/**
* Callback for when the backdrop is clicked.
*/
Expand All @@ -29,14 +35,19 @@ export const Backdrop: FC<BackdropProps> = ({
zIndex = 998,
portalIndex = 0,
className,
theme: customTheme,
onClick
}) => (
<motion.div
className={classNames(css.backdrop, className)}
initial={{ opacity: 0 }}
animate={{ opacity: 0.8 - (portalIndex as number) / 10 }}
exit={{ opacity: 0 }}
style={{ zIndex }}
onClick={onClick}
/>
);
}) => {
const theme = useComponentTheme<BackdropTheme>('backdrop', customTheme);

return (
<motion.div
className={cn(theme.base, className)}
initial={{ opacity: 0 }}
animate={{ opacity: theme.opacity - (portalIndex as number) / 10 }}
exit={{ opacity: 0 }}
style={{ zIndex }}
onClick={onClick}
/>
);
};
14 changes: 14 additions & 0 deletions src/layers/Backdrop/BackdropTheme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface BackdropTheme {
base: string;
opacity: number;
}

export const backdropTheme: BackdropTheme = {
base: 'fixed top-0 left-0 w-full h-full opacity-0 select-none bg-black',
opacity: 0.8
};

export const legacyBackdropTheme: BackdropTheme = {
base: 'fixed top-0 left-0 w-full h-full opacity-0 select-none bg-[var(--color-layer-transparent)]',
opacity: 0.8
};
1 change: 1 addition & 0 deletions src/layers/Backdrop/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Backdrop';
export * from './BackdropTheme';
2 changes: 2 additions & 0 deletions src/utils/Theme/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import React, {
createContext,
FC,
Expand Down
12 changes: 9 additions & 3 deletions src/utils/Theme/themes/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ import {
TooltipTheme,
CalloutTheme,
calloutTheme,
legacyCalloutTheme
legacyCalloutTheme,
BackdropTheme,
backdropTheme,
legacyBackdropTheme
} from '@/layers';

import {
Expand Down Expand Up @@ -194,6 +197,7 @@ export interface ReablocksTheme {
breadcrumbs: BreadcrumbsTheme;
stepper: StepperTheme;
callout: CalloutTheme;
backdrop: BackdropTheme;
};
}

Expand Down Expand Up @@ -242,7 +246,8 @@ export const theme: ReablocksTheme = {
jsonTree: jsonTreeTheme,
breadcrumbs: breadcrumbsTheme,
stepper: stepperTheme,
callout: calloutTheme
callout: calloutTheme,
backdrop: backdropTheme
}
};

Expand Down Expand Up @@ -291,6 +296,7 @@ export const legacyThemeVars: ReablocksTheme = {
jsonTree: legacyJsonTreeTheme,
breadcrumbs: legacyBreadcrumbTheme,
stepper: legacyStepperTheme,
callout: legacyCalloutTheme
callout: legacyCalloutTheme,
backdrop: legacyBackdropTheme
}
};

0 comments on commit 5ac8f22

Please sign in to comment.