Merge pull request #3611 from glitch-soc/glitch-soc/merge-upstream
Merge upstream changes up to a1474e9316
This commit is contained in:
23 files changed
+797
-41
No files matched your search
@@ -24,6 +24,7 @@ export interface ApiImageAttachmentJSON extends BaseApiMediaAttachmentJSON {
|
||||
meta: {
|
||||
original: ApiImageAttachmentMetaJSON;
|
||||
small: ApiImageAttachmentMetaJSON;
|
||||
focus?: ApiFocusAttachmentMetaJSON;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -42,10 +43,7 @@ export interface ApiVideoAttachmentJSON extends BaseApiMediaAttachmentJSON {
|
||||
colors: ApiColorsAttachmentMetaJSON;
|
||||
original: ApiVideoAttachmentMetaJSON;
|
||||
small: ApiImageAttachmentMetaJSON;
|
||||
focus: {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
focus?: ApiFocusAttachmentMetaJSON;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -54,6 +52,7 @@ export interface ApiGifvAttachmentJSON extends BaseApiMediaAttachmentJSON {
|
||||
meta: {
|
||||
original: ApiVideoAttachmentMetaJSON;
|
||||
small: ApiImageAttachmentMetaJSON;
|
||||
focus?: ApiFocusAttachmentMetaJSON;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,3 +88,8 @@ export interface ApiColorsAttachmentMetaJSON {
|
||||
foreground: string;
|
||||
accent: string;
|
||||
}
|
||||
|
||||
export interface ApiFocusAttachmentMetaJSON {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
@@ -23,12 +23,12 @@ export const textAtCursorMatchesToken = (
|
||||
word = word.trim();
|
||||
|
||||
if (word.length < 3 || (word[0] && !searchTokens.includes(word[0]))) {
|
||||
return [null, null];
|
||||
return [null, null] as const;
|
||||
}
|
||||
|
||||
if (word.length > 0) {
|
||||
return [left + 1, word];
|
||||
return [left + 1, word] as const;
|
||||
} else {
|
||||
return [null, null];
|
||||
return [null, null] as const;
|
||||
}
|
||||
};
|
||||
@@ -153,7 +153,7 @@ const AutosuggestTextarea = forwardRef(({
|
||||
}
|
||||
}, [lang]);
|
||||
|
||||
const renderSuggestion = (suggestion, i) => {
|
||||
const renderSuggestion = useCallback((suggestion, i) => {
|
||||
let inner, key;
|
||||
|
||||
if (suggestion.type === 'emoji') {
|
||||
@@ -172,7 +172,7 @@ const AutosuggestTextarea = forwardRef(({
|
||||
{inner}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
}, [selectedSuggestion, handleSuggestionClick]);
|
||||
|
||||
const handleRef = useCallback((element) => {
|
||||
textareaRef.current = element;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
@use '@/styles/mastodon/mixins';
|
||||
|
||||
.menu {
|
||||
@include mixins.elevation-1;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: var(--space-2xs) 0;
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--color-bg-primary);
|
||||
overflow: hidden;
|
||||
|
||||
&[data-elevation='2'] {
|
||||
@include mixins.elevation-2;
|
||||
}
|
||||
|
||||
> hr {
|
||||
height: 1px;
|
||||
background-color: var(--color-border-primary);
|
||||
margin: var(--space-2xs) var(--space-sm);
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
.menuItem {
|
||||
@include mixins.type-body-compact;
|
||||
|
||||
--cursor: pointer;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-xs);
|
||||
padding: var(--space-xs) var(--space-sm);
|
||||
cursor: var(--cursor);
|
||||
transition:
|
||||
background 200ms,
|
||||
color 200ms;
|
||||
|
||||
label {
|
||||
cursor: inherit;
|
||||
font-weight: inherit;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: color-mix(
|
||||
in srgb,
|
||||
var(--color-bg-primary) 90%,
|
||||
var(--color-bg-inverted)
|
||||
);
|
||||
}
|
||||
|
||||
&:active,
|
||||
.menuItemActive {
|
||||
background-color: var(--color-bg-inverted);
|
||||
color: var(--color-text-inverted);
|
||||
}
|
||||
|
||||
&:has(:disabled) {
|
||||
--cursor: not-allowed;
|
||||
|
||||
background-color: var(--color-bg-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.menuItemButton {
|
||||
appearance: none;
|
||||
background: none;
|
||||
border: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.menu > hr {
|
||||
height: 1px;
|
||||
background-color: var(--color-border-primary);
|
||||
margin: var(--space-2xs) var(--space-sm);
|
||||
border: none;
|
||||
width: calc(100% - (2 * var(--space-sm)));
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
import {
|
||||
MoonIcon,
|
||||
NumberCircleOneIcon,
|
||||
NumberCircleTwoIcon,
|
||||
SunIcon,
|
||||
} from '@phosphor-icons/react';
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { action } from 'storybook/actions';
|
||||
|
||||
import { useToggle } from '@/flavours/glitch/hooks/useToggle';
|
||||
|
||||
import { Button } from '../button/redesign';
|
||||
import { ToggleField } from '../form_fields/redesign';
|
||||
import { Icon } from '../icon';
|
||||
|
||||
import type { DropdownProps } from './redesign';
|
||||
import {
|
||||
Dropdown,
|
||||
DropdownItem,
|
||||
DropdownItemButton,
|
||||
DropdownPopover,
|
||||
} from './redesign';
|
||||
|
||||
const meta = {
|
||||
title: 'Redesign/Dropdown',
|
||||
args: {
|
||||
elevation: 1,
|
||||
},
|
||||
argTypes: {
|
||||
elevation: {
|
||||
control: 'inline-radio',
|
||||
options: [1, 2],
|
||||
},
|
||||
},
|
||||
} satisfies Meta<Omit<DropdownProps<'div'>, 'children'>>;
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof meta>;
|
||||
|
||||
const handleMenuItemClick = action('menu item click');
|
||||
|
||||
export const Simple: Story = {
|
||||
render(args) {
|
||||
return (
|
||||
<Dropdown {...args}>
|
||||
<DropdownItemButton
|
||||
icon={NumberCircleOneIcon}
|
||||
onClick={handleMenuItemClick}
|
||||
>
|
||||
First item
|
||||
</DropdownItemButton>
|
||||
<DropdownItemButton
|
||||
icon={NumberCircleTwoIcon}
|
||||
onClick={handleMenuItemClick}
|
||||
>
|
||||
Second item
|
||||
</DropdownItemButton>
|
||||
</Dropdown>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export const Popover: Story = {
|
||||
render(args) {
|
||||
const [ref, setRef] = useState<HTMLButtonElement | null>(null);
|
||||
const [open, { onToggle, onFalse }] = useToggle();
|
||||
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||
<Button ref={setRef} onClick={onToggle}>
|
||||
Click to show dropdown
|
||||
</Button>
|
||||
|
||||
<DropdownPopover
|
||||
reference={ref}
|
||||
isOpen={open}
|
||||
onClose={onFalse}
|
||||
{...args}
|
||||
>
|
||||
<DropdownItemButton
|
||||
icon={NumberCircleOneIcon}
|
||||
onClick={handleMenuItemClick}
|
||||
>
|
||||
First item
|
||||
</DropdownItemButton>
|
||||
<DropdownItemButton
|
||||
icon={NumberCircleTwoIcon}
|
||||
onClick={handleMenuItemClick}
|
||||
>
|
||||
Second item
|
||||
</DropdownItemButton>
|
||||
</DropdownPopover>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export const Controls: Story = {
|
||||
render(args) {
|
||||
const [sun, { onToggle }] = useToggle();
|
||||
return (
|
||||
<Dropdown {...args}>
|
||||
<DropdownItemButton onClick={handleMenuItemClick}>
|
||||
First item
|
||||
</DropdownItemButton>
|
||||
|
||||
<hr />
|
||||
|
||||
<DropdownItem>
|
||||
{sun ? (
|
||||
<Icon id='sun' icon={SunIcon} />
|
||||
) : (
|
||||
<Icon id='moon' icon={MoonIcon} />
|
||||
)}
|
||||
<ToggleField label='Daytime toggle' size='sm' onChange={onToggle} />
|
||||
</DropdownItem>
|
||||
</Dropdown>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,133 @@
|
||||
import type React from 'react';
|
||||
|
||||
import classNames from 'classnames';
|
||||
|
||||
import type { Merge } from 'type-fest';
|
||||
|
||||
import { Icon } from '../icon';
|
||||
import type { IconProp } from '../icon';
|
||||
import type { PopoverProps } from '../popover';
|
||||
import { Popover } from '../popover';
|
||||
|
||||
import classes from './redesign.module.scss';
|
||||
|
||||
export const menuItemClass = classes.menuItem;
|
||||
|
||||
export type DropdownProps<As extends React.ElementType> = Merge<
|
||||
{
|
||||
as?: As;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
elevation?: 1 | 2;
|
||||
maxWidth?: number | string;
|
||||
style?: React.CSSProperties;
|
||||
},
|
||||
React.ComponentProps<As>
|
||||
>;
|
||||
|
||||
export const DropdownPopover = <As extends React.ElementType>({
|
||||
isOpen,
|
||||
onClose,
|
||||
reference,
|
||||
popoverElement,
|
||||
container,
|
||||
placement,
|
||||
offset = 4,
|
||||
flip,
|
||||
strategy,
|
||||
matchReferenceWidth,
|
||||
closeOnClickOutside,
|
||||
children,
|
||||
...props
|
||||
}: DropdownProps<As> & Omit<PopoverProps, 'children'>) => {
|
||||
const popoverProps = {
|
||||
isOpen,
|
||||
onClose,
|
||||
reference,
|
||||
popoverElement,
|
||||
container,
|
||||
placement,
|
||||
offset,
|
||||
flip,
|
||||
strategy,
|
||||
matchReferenceWidth,
|
||||
closeOnClickOutside,
|
||||
};
|
||||
return (
|
||||
<Popover {...popoverProps}>
|
||||
{({ props: popoverChildProps }) => (
|
||||
<Dropdown {...props} {...popoverChildProps}>
|
||||
{children}
|
||||
</Dropdown>
|
||||
)}
|
||||
</Popover>
|
||||
);
|
||||
};
|
||||
|
||||
export const Dropdown = <As extends React.ElementType>({
|
||||
as: asComp,
|
||||
children,
|
||||
className,
|
||||
elevation = 1,
|
||||
maxWidth,
|
||||
style,
|
||||
...props
|
||||
}: DropdownProps<As>) => {
|
||||
const Component = asComp ?? 'div';
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
className={classNames(className, classes.menu)}
|
||||
data-elevation={elevation}
|
||||
style={{
|
||||
maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth,
|
||||
...style,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Component>
|
||||
);
|
||||
};
|
||||
|
||||
type DropdownItemProps<As extends React.ElementType> = Merge<
|
||||
{ as?: As; children?: React.ReactNode; className?: string; active?: boolean },
|
||||
React.ComponentPropsWithoutRef<As>
|
||||
>;
|
||||
|
||||
export const DropdownItem = <As extends React.ElementType>({
|
||||
active,
|
||||
as: AsComp,
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}: DropdownItemProps<As>) => {
|
||||
const Component = AsComp ?? 'div';
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
className={classNames(
|
||||
className,
|
||||
classes.menuItem,
|
||||
active && classes.menuItemActive,
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</Component>
|
||||
);
|
||||
};
|
||||
|
||||
export const DropdownItemButton: React.FC<
|
||||
{ icon?: IconProp } & React.ComponentProps<'button'>
|
||||
> = ({ icon, children, className, ...props }) => {
|
||||
return (
|
||||
<DropdownItem
|
||||
type='button'
|
||||
{...props}
|
||||
as='button'
|
||||
className={classNames(className, classes.menuItemButton)}
|
||||
>
|
||||
{icon && <Icon id='menu' icon={icon} />}
|
||||
{children}
|
||||
</DropdownItem>
|
||||
);
|
||||
};
|
||||
@@ -95,13 +95,18 @@ export interface PopoverProps {
|
||||
* enable it to be sized and positioned. The `ref` prop
|
||||
* is not passed when the `popoverElement` prop is provided.
|
||||
*/
|
||||
props: Record<string, unknown> & {
|
||||
ref?: React.RefCallback<HTMLElement>;
|
||||
style: React.CSSProperties;
|
||||
};
|
||||
props: PopoverChildProps;
|
||||
}) => React.ReactNode;
|
||||
}
|
||||
|
||||
export interface PopoverChildProps {
|
||||
ref?: React.RefCallback<HTMLElement>;
|
||||
style: React.CSSProperties;
|
||||
'data-popover-placement': Placement;
|
||||
'data-popover-reference-hidden'?: boolean;
|
||||
'data-popover-escaped'?: boolean;
|
||||
}
|
||||
|
||||
export const Popover: React.FC<PopoverProps> = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
|
||||
@@ -56,13 +56,15 @@ const getFrequentlyUsedLanguages = createSelector(
|
||||
|
||||
const isTextLongEnoughForGuess = (text: string) => text.length > 20;
|
||||
|
||||
const LanguageDropdownMenu: React.FC<{
|
||||
const emptyArray: Language[] = [];
|
||||
|
||||
export const LanguageDropdownMenu: React.FC<{
|
||||
value: string;
|
||||
guess?: string;
|
||||
guess: string;
|
||||
onClose: () => void;
|
||||
onChange: (arg0: string) => void;
|
||||
}> = ({ value, guess, onClose, onChange }) => {
|
||||
const languages = preloadedLanguages as Language[];
|
||||
const languages = preloadedLanguages ?? emptyArray;
|
||||
const intl = useIntl();
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const nodeRef = useRef<HTMLDivElement>(null);
|
||||
@@ -317,7 +319,7 @@ export const LanguageDropdown: React.FC = () => {
|
||||
const text = useAppSelector((state) => state.compose.get('text') as string);
|
||||
|
||||
const current =
|
||||
(preloadedLanguages as Language[]).find((lang) => lang[0] === value) ?? [];
|
||||
(preloadedLanguages ?? []).find((lang) => lang[0] === value) ?? [];
|
||||
|
||||
const handleMouseDown = useCallback(() => {
|
||||
if (!open && document.activeElement instanceof HTMLElement) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
|
||||
import { STORE_HYDRATE } from '../actions/store';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
accept_content_types: [],
|
||||
accept_content_types: ImmutableList(),
|
||||
});
|
||||
|
||||
export default function meta(state = initialState, action) {
|
||||
|
||||
@@ -30,7 +30,7 @@ export const selectPlainStatus = createAppSelector(
|
||||
export const selectAccountStatus = createAppSelector(
|
||||
[
|
||||
selectPlainStatus,
|
||||
(state, statusId: string) => {
|
||||
(state, statusId?: string | null) => {
|
||||
const accountId = state.statuses.getIn([statusId, 'account']);
|
||||
if (typeof accountId !== 'string') {
|
||||
return null;
|
||||
|
||||
@@ -24,6 +24,7 @@ export interface ApiImageAttachmentJSON extends BaseApiMediaAttachmentJSON {
|
||||
meta: {
|
||||
original: ApiImageAttachmentMetaJSON;
|
||||
small: ApiImageAttachmentMetaJSON;
|
||||
focus?: ApiFocusAttachmentMetaJSON;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -42,10 +43,7 @@ export interface ApiVideoAttachmentJSON extends BaseApiMediaAttachmentJSON {
|
||||
colors: ApiColorsAttachmentMetaJSON;
|
||||
original: ApiVideoAttachmentMetaJSON;
|
||||
small: ApiImageAttachmentMetaJSON;
|
||||
focus: {
|
||||
x: number;
|
||||
y: number;
|
||||
};
|
||||
focus?: ApiFocusAttachmentMetaJSON;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -54,6 +52,7 @@ export interface ApiGifvAttachmentJSON extends BaseApiMediaAttachmentJSON {
|
||||
meta: {
|
||||
original: ApiVideoAttachmentMetaJSON;
|
||||
small: ApiImageAttachmentMetaJSON;
|
||||
focus?: ApiFocusAttachmentMetaJSON;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,3 +88,8 @@ export interface ApiColorsAttachmentMetaJSON {
|
||||
foreground: string;
|
||||
accent: string;
|
||||
}
|
||||
|
||||
export interface ApiFocusAttachmentMetaJSON {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
@@ -23,12 +23,12 @@ export const textAtCursorMatchesToken = (
|
||||
word = word.trim();
|
||||
|
||||
if (word.length < 3 || (word[0] && !searchTokens.includes(word[0]))) {
|
||||
return [null, null];
|
||||
return [null, null] as const;
|
||||
}
|
||||
|
||||
if (word.length > 0) {
|
||||
return [left + 1, word];
|
||||
return [left + 1, word] as const;
|
||||
} else {
|
||||
return [null, null];
|
||||
return [null, null] as const;
|
||||
}
|
||||
};
|
||||
@@ -153,7 +153,7 @@ const AutosuggestTextarea = forwardRef(({
|
||||
}
|
||||
}, [lang]);
|
||||
|
||||
const renderSuggestion = (suggestion, i) => {
|
||||
const renderSuggestion = useCallback((suggestion, i) => {
|
||||
let inner, key;
|
||||
|
||||
if (suggestion.type === 'emoji') {
|
||||
@@ -172,7 +172,7 @@ const AutosuggestTextarea = forwardRef(({
|
||||
{inner}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
}, [selectedSuggestion, handleSuggestionClick]);
|
||||
|
||||
const handleRef = useCallback((element) => {
|
||||
textareaRef.current = element;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
@use '@/styles/mastodon/mixins';
|
||||
|
||||
.menu {
|
||||
@include mixins.elevation-1;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: var(--space-2xs) 0;
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--color-bg-primary);
|
||||
overflow: hidden;
|
||||
|
||||
&[data-elevation='2'] {
|
||||
@include mixins.elevation-2;
|
||||
}
|
||||
|
||||
> hr {
|
||||
height: 1px;
|
||||
background-color: var(--color-border-primary);
|
||||
margin: var(--space-2xs) var(--space-sm);
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
.menuItem {
|
||||
@include mixins.type-body-compact;
|
||||
|
||||
--cursor: pointer;
|
||||
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-xs);
|
||||
padding: var(--space-xs) var(--space-sm);
|
||||
cursor: var(--cursor);
|
||||
transition:
|
||||
background 200ms,
|
||||
color 200ms;
|
||||
|
||||
label {
|
||||
cursor: inherit;
|
||||
font-weight: inherit;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: color-mix(
|
||||
in srgb,
|
||||
var(--color-bg-primary) 90%,
|
||||
var(--color-bg-inverted)
|
||||
);
|
||||
}
|
||||
|
||||
&:active,
|
||||
.menuItemActive {
|
||||
background-color: var(--color-bg-inverted);
|
||||
color: var(--color-text-inverted);
|
||||
}
|
||||
|
||||
&:has(:disabled) {
|
||||
--cursor: not-allowed;
|
||||
|
||||
background-color: var(--color-bg-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.menuItemButton {
|
||||
appearance: none;
|
||||
background: none;
|
||||
border: none;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.menu > hr {
|
||||
height: 1px;
|
||||
background-color: var(--color-border-primary);
|
||||
margin: var(--space-2xs) var(--space-sm);
|
||||
border: none;
|
||||
width: calc(100% - (2 * var(--space-sm)));
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
import {
|
||||
MoonIcon,
|
||||
NumberCircleOneIcon,
|
||||
NumberCircleTwoIcon,
|
||||
SunIcon,
|
||||
} from '@phosphor-icons/react';
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { action } from 'storybook/actions';
|
||||
|
||||
import { useToggle } from '@/mastodon/hooks/useToggle';
|
||||
|
||||
import { Button } from '../button/redesign';
|
||||
import { ToggleField } from '../form_fields/redesign';
|
||||
import { Icon } from '../icon';
|
||||
|
||||
import type { DropdownProps } from './redesign';
|
||||
import {
|
||||
Dropdown,
|
||||
DropdownItem,
|
||||
DropdownItemButton,
|
||||
DropdownPopover,
|
||||
} from './redesign';
|
||||
|
||||
const meta = {
|
||||
title: 'Redesign/Dropdown',
|
||||
args: {
|
||||
elevation: 1,
|
||||
},
|
||||
argTypes: {
|
||||
elevation: {
|
||||
control: 'inline-radio',
|
||||
options: [1, 2],
|
||||
},
|
||||
},
|
||||
} satisfies Meta<Omit<DropdownProps<'div'>, 'children'>>;
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<typeof meta>;
|
||||
|
||||
const handleMenuItemClick = action('menu item click');
|
||||
|
||||
export const Simple: Story = {
|
||||
render(args) {
|
||||
return (
|
||||
<Dropdown {...args}>
|
||||
<DropdownItemButton
|
||||
icon={NumberCircleOneIcon}
|
||||
onClick={handleMenuItemClick}
|
||||
>
|
||||
First item
|
||||
</DropdownItemButton>
|
||||
<DropdownItemButton
|
||||
icon={NumberCircleTwoIcon}
|
||||
onClick={handleMenuItemClick}
|
||||
>
|
||||
Second item
|
||||
</DropdownItemButton>
|
||||
</Dropdown>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export const Popover: Story = {
|
||||
render(args) {
|
||||
const [ref, setRef] = useState<HTMLButtonElement | null>(null);
|
||||
const [open, { onToggle, onFalse }] = useToggle();
|
||||
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||
<Button ref={setRef} onClick={onToggle}>
|
||||
Click to show dropdown
|
||||
</Button>
|
||||
|
||||
<DropdownPopover
|
||||
reference={ref}
|
||||
isOpen={open}
|
||||
onClose={onFalse}
|
||||
{...args}
|
||||
>
|
||||
<DropdownItemButton
|
||||
icon={NumberCircleOneIcon}
|
||||
onClick={handleMenuItemClick}
|
||||
>
|
||||
First item
|
||||
</DropdownItemButton>
|
||||
<DropdownItemButton
|
||||
icon={NumberCircleTwoIcon}
|
||||
onClick={handleMenuItemClick}
|
||||
>
|
||||
Second item
|
||||
</DropdownItemButton>
|
||||
</DropdownPopover>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export const Controls: Story = {
|
||||
render(args) {
|
||||
const [sun, { onToggle }] = useToggle();
|
||||
return (
|
||||
<Dropdown {...args}>
|
||||
<DropdownItemButton onClick={handleMenuItemClick}>
|
||||
First item
|
||||
</DropdownItemButton>
|
||||
|
||||
<hr />
|
||||
|
||||
<DropdownItem>
|
||||
{sun ? (
|
||||
<Icon id='sun' icon={SunIcon} />
|
||||
) : (
|
||||
<Icon id='moon' icon={MoonIcon} />
|
||||
)}
|
||||
<ToggleField label='Daytime toggle' size='sm' onChange={onToggle} />
|
||||
</DropdownItem>
|
||||
</Dropdown>
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,133 @@
|
||||
import type React from 'react';
|
||||
|
||||
import classNames from 'classnames';
|
||||
|
||||
import type { Merge } from 'type-fest';
|
||||
|
||||
import { Icon } from '../icon';
|
||||
import type { IconProp } from '../icon';
|
||||
import type { PopoverProps } from '../popover';
|
||||
import { Popover } from '../popover';
|
||||
|
||||
import classes from './redesign.module.scss';
|
||||
|
||||
export const menuItemClass = classes.menuItem;
|
||||
|
||||
export type DropdownProps<As extends React.ElementType> = Merge<
|
||||
{
|
||||
as?: As;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
elevation?: 1 | 2;
|
||||
maxWidth?: number | string;
|
||||
style?: React.CSSProperties;
|
||||
},
|
||||
React.ComponentProps<As>
|
||||
>;
|
||||
|
||||
export const DropdownPopover = <As extends React.ElementType>({
|
||||
isOpen,
|
||||
onClose,
|
||||
reference,
|
||||
popoverElement,
|
||||
container,
|
||||
placement,
|
||||
offset = 4,
|
||||
flip,
|
||||
strategy,
|
||||
matchReferenceWidth,
|
||||
closeOnClickOutside,
|
||||
children,
|
||||
...props
|
||||
}: DropdownProps<As> & Omit<PopoverProps, 'children'>) => {
|
||||
const popoverProps = {
|
||||
isOpen,
|
||||
onClose,
|
||||
reference,
|
||||
popoverElement,
|
||||
container,
|
||||
placement,
|
||||
offset,
|
||||
flip,
|
||||
strategy,
|
||||
matchReferenceWidth,
|
||||
closeOnClickOutside,
|
||||
};
|
||||
return (
|
||||
<Popover {...popoverProps}>
|
||||
{({ props: popoverChildProps }) => (
|
||||
<Dropdown {...props} {...popoverChildProps}>
|
||||
{children}
|
||||
</Dropdown>
|
||||
)}
|
||||
</Popover>
|
||||
);
|
||||
};
|
||||
|
||||
export const Dropdown = <As extends React.ElementType>({
|
||||
as: asComp,
|
||||
children,
|
||||
className,
|
||||
elevation = 1,
|
||||
maxWidth,
|
||||
style,
|
||||
...props
|
||||
}: DropdownProps<As>) => {
|
||||
const Component = asComp ?? 'div';
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
className={classNames(className, classes.menu)}
|
||||
data-elevation={elevation}
|
||||
style={{
|
||||
maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth,
|
||||
...style,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Component>
|
||||
);
|
||||
};
|
||||
|
||||
type DropdownItemProps<As extends React.ElementType> = Merge<
|
||||
{ as?: As; children?: React.ReactNode; className?: string; active?: boolean },
|
||||
React.ComponentPropsWithoutRef<As>
|
||||
>;
|
||||
|
||||
export const DropdownItem = <As extends React.ElementType>({
|
||||
active,
|
||||
as: AsComp,
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}: DropdownItemProps<As>) => {
|
||||
const Component = AsComp ?? 'div';
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
className={classNames(
|
||||
className,
|
||||
classes.menuItem,
|
||||
active && classes.menuItemActive,
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</Component>
|
||||
);
|
||||
};
|
||||
|
||||
export const DropdownItemButton: React.FC<
|
||||
{ icon?: IconProp } & React.ComponentProps<'button'>
|
||||
> = ({ icon, children, className, ...props }) => {
|
||||
return (
|
||||
<DropdownItem
|
||||
type='button'
|
||||
{...props}
|
||||
as='button'
|
||||
className={classNames(className, classes.menuItemButton)}
|
||||
>
|
||||
{icon && <Icon id='menu' icon={icon} />}
|
||||
{children}
|
||||
</DropdownItem>
|
||||
);
|
||||
};
|
||||
@@ -95,13 +95,18 @@ export interface PopoverProps {
|
||||
* enable it to be sized and positioned. The `ref` prop
|
||||
* is not passed when the `popoverElement` prop is provided.
|
||||
*/
|
||||
props: Record<string, unknown> & {
|
||||
ref?: React.RefCallback<HTMLElement>;
|
||||
style: React.CSSProperties;
|
||||
};
|
||||
props: PopoverChildProps;
|
||||
}) => React.ReactNode;
|
||||
}
|
||||
|
||||
export interface PopoverChildProps {
|
||||
ref?: React.RefCallback<HTMLElement>;
|
||||
style: React.CSSProperties;
|
||||
'data-popover-placement': Placement;
|
||||
'data-popover-reference-hidden'?: boolean;
|
||||
'data-popover-escaped'?: boolean;
|
||||
}
|
||||
|
||||
export const Popover: React.FC<PopoverProps> = ({
|
||||
isOpen,
|
||||
onClose,
|
||||
|
||||
@@ -56,13 +56,15 @@ const getFrequentlyUsedLanguages = createSelector(
|
||||
|
||||
const isTextLongEnoughForGuess = (text: string) => text.length > 20;
|
||||
|
||||
const LanguageDropdownMenu: React.FC<{
|
||||
const emptyArray: Language[] = [];
|
||||
|
||||
export const LanguageDropdownMenu: React.FC<{
|
||||
value: string;
|
||||
guess?: string;
|
||||
guess: string;
|
||||
onClose: () => void;
|
||||
onChange: (arg0: string) => void;
|
||||
}> = ({ value, guess, onClose, onChange }) => {
|
||||
const languages = preloadedLanguages as Language[];
|
||||
const languages = preloadedLanguages ?? emptyArray;
|
||||
const intl = useIntl();
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
const nodeRef = useRef<HTMLDivElement>(null);
|
||||
@@ -317,7 +319,7 @@ export const LanguageDropdown: React.FC = () => {
|
||||
const text = useAppSelector((state) => state.compose.get('text') as string);
|
||||
|
||||
const current =
|
||||
(preloadedLanguages as Language[]).find((lang) => lang[0] === value) ?? [];
|
||||
(preloadedLanguages ?? []).find((lang) => lang[0] === value) ?? [];
|
||||
|
||||
const handleMouseDown = useCallback(() => {
|
||||
if (!open && document.activeElement instanceof HTMLElement) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
|
||||
import { STORE_HYDRATE } from '../actions/store';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
accept_content_types: [],
|
||||
accept_content_types: ImmutableList(),
|
||||
});
|
||||
|
||||
export default function meta(state = initialState, action) {
|
||||
|
||||
@@ -30,7 +30,7 @@ export const selectPlainStatus = createAppSelector(
|
||||
export const selectAccountStatus = createAppSelector(
|
||||
[
|
||||
selectPlainStatus,
|
||||
(state, statusId: string) => {
|
||||
(state, statusId?: string | null) => {
|
||||
const accountId = state.statuses.getIn([statusId, 'account']);
|
||||
if (typeof accountId !== 'string') {
|
||||
return null;
|
||||
|
||||
@@ -2,9 +2,16 @@ import type { CompactEmoji } from 'emojibase';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { action } from 'storybook/actions';
|
||||
|
||||
import type { MediaAttachmentType } from '@/mastodon/api_types/media_attachments';
|
||||
import { toSupportedLocale } from '@/mastodon/features/emoji/locale';
|
||||
|
||||
import { customEmojiFactory, relationshipsFactoryAPI } from './factories';
|
||||
import {
|
||||
customEmojiFactory,
|
||||
mediaAttachmentFactoryAPI,
|
||||
relationshipsFactoryAPI,
|
||||
} from './factories';
|
||||
|
||||
const mediaStorageMap = new Map<string, File>();
|
||||
|
||||
export const mockHandlers = {
|
||||
mute: http.post<{ id: string }>('/api/v1/accounts/:id/mute', ({ params }) => {
|
||||
@@ -43,6 +50,53 @@ export const mockHandlers = {
|
||||
);
|
||||
},
|
||||
),
|
||||
mediaUpload: http.post('/api/v2/media', async ({ request }) => {
|
||||
action('uploaded media')();
|
||||
|
||||
const formData = await request.formData();
|
||||
const file = formData.get('file');
|
||||
if (!file) {
|
||||
return new HttpResponse('Missing media', { status: 400 });
|
||||
}
|
||||
|
||||
if (!(file instanceof File)) {
|
||||
return new HttpResponse('Media is not file', { status: 400 });
|
||||
}
|
||||
|
||||
const { type: mimeType } = file;
|
||||
const id = mediaStorageMap.size.toString();
|
||||
mediaStorageMap.set(id, file);
|
||||
let type: MediaAttachmentType = 'unknown';
|
||||
if (mimeType === 'image/gif') {
|
||||
type = 'gifv';
|
||||
} else if (mimeType.startsWith('image/')) {
|
||||
type = 'image';
|
||||
} else if (mimeType.startsWith('video/')) {
|
||||
type = 'video';
|
||||
} else if (mimeType.startsWith('audio/')) {
|
||||
type = 'audio';
|
||||
}
|
||||
|
||||
return HttpResponse.json(
|
||||
mediaAttachmentFactoryAPI({
|
||||
id,
|
||||
type,
|
||||
url: `/mock_media/${id}`,
|
||||
preview_url: `/mock_media/${id}`,
|
||||
}),
|
||||
);
|
||||
}),
|
||||
mediaGet: http.get<{ id: string }>('/mock_media/:id', async ({ params }) => {
|
||||
const { id } = params;
|
||||
action(`getting media id ${id}`)();
|
||||
|
||||
const media = mediaStorageMap.get(id);
|
||||
if (!media) {
|
||||
return new HttpResponse('Not found', { status: 404 });
|
||||
}
|
||||
|
||||
return HttpResponse.arrayBuffer(await media.arrayBuffer());
|
||||
}),
|
||||
emojiCustomData: http.get('/api/v1/custom_emojis', () => {
|
||||
action('fetching custom emoji data')();
|
||||
return HttpResponse.json([customEmojiFactory()]);
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
"@gamestdio/websocket": "^0.3.2",
|
||||
"@github/webauthn-json": "^2.1.1",
|
||||
"@optimize-lodash/rollup-plugin": "^6.0.0",
|
||||
"@phosphor-icons/react": "^2.1.10",
|
||||
"@react-spring/web": "^10.1.1",
|
||||
"@reduxjs/toolkit": "^2.0.1",
|
||||
"@rolldown/plugin-babel": "^0.2.2",
|
||||
|
||||
@@ -2977,6 +2977,7 @@ __metadata:
|
||||
"@gamestdio/websocket": "npm:^0.3.2"
|
||||
"@github/webauthn-json": "npm:^2.1.1"
|
||||
"@optimize-lodash/rollup-plugin": "npm:^6.0.0"
|
||||
"@phosphor-icons/react": "npm:^2.1.10"
|
||||
"@react-spring/web": "npm:^10.1.1"
|
||||
"@reduxjs/toolkit": "npm:^2.0.1"
|
||||
"@rolldown/plugin-babel": "npm:^0.2.2"
|
||||
@@ -3739,6 +3740,16 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@phosphor-icons/react@npm:^2.1.10":
|
||||
version: 2.1.10
|
||||
resolution: "@phosphor-icons/react@npm:2.1.10"
|
||||
peerDependencies:
|
||||
react: ">= 16.8"
|
||||
react-dom: ">= 16.8"
|
||||
checksum: 10c0/9a469e1bdcabcd3db02eda13142d57be250847ebbeb82b33c8900580a6a23ed4f411dbb9b9deacef726ff3fa8ffc960c8868b518e448bd2cee654cedf3fa4bda
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@pinojs/redact@npm:^0.4.0":
|
||||
version: 0.4.0
|
||||
resolution: "@pinojs/redact@npm:0.4.0"
|
||||
|
||||
Reference in new issue
Block a user