From c47bf15bd93ea857a4d98b0090a878d36593e1a7 Mon Sep 17 00:00:00 2001 From: Echo Date: Thu, 30 Jul 2026 12:15:10 +0200 Subject: [PATCH 1/6] Redesign dropdown (#39991) --- .../components/dropdown/redesign.module.scss | 79 +++++++++++ .../components/dropdown/redesign.stories.tsx | 123 +++++++++++++++++ .../mastodon/components/dropdown/redesign.tsx | 125 ++++++++++++++++++ package.json | 1 + yarn.lock | 11 ++ 5 files changed, 339 insertions(+) create mode 100644 app/javascript/mastodon/components/dropdown/redesign.module.scss create mode 100644 app/javascript/mastodon/components/dropdown/redesign.stories.tsx create mode 100644 app/javascript/mastodon/components/dropdown/redesign.tsx diff --git a/app/javascript/mastodon/components/dropdown/redesign.module.scss b/app/javascript/mastodon/components/dropdown/redesign.module.scss new file mode 100644 index 0000000000..3b86410b34 --- /dev/null +++ b/app/javascript/mastodon/components/dropdown/redesign.module.scss @@ -0,0 +1,79 @@ +@use '@/styles/mastodon/mixins'; + +.menu { + @include mixins.elevation-1; + + display: flex; + flex-direction: column; + align-items: flex-start; + 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))); +} diff --git a/app/javascript/mastodon/components/dropdown/redesign.stories.tsx b/app/javascript/mastodon/components/dropdown/redesign.stories.tsx new file mode 100644 index 0000000000..b56e8df3dc --- /dev/null +++ b/app/javascript/mastodon/components/dropdown/redesign.stories.tsx @@ -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, 'children'>>; + +export default meta; + +type Story = StoryObj; + +const handleMenuItemClick = action('menu item click'); + +export const Simple: Story = { + render(args) { + return ( + + + First item + + + Second item + + + ); + }, +}; + +export const Popover: Story = { + render(args) { + const [ref, setRef] = useState(null); + const [open, { onToggle, onFalse }] = useToggle(); + + return ( +
+ + + + + First item + + + Second item + + +
+ ); + }, +}; + +export const Controls: Story = { + render(args) { + const [sun, { onToggle }] = useToggle(); + return ( + + + First item + + +
+ + + {sun ? ( + + ) : ( + + )} + + +
+ ); + }, +}; diff --git a/app/javascript/mastodon/components/dropdown/redesign.tsx b/app/javascript/mastodon/components/dropdown/redesign.tsx new file mode 100644 index 0000000000..afa3553c3c --- /dev/null +++ b/app/javascript/mastodon/components/dropdown/redesign.tsx @@ -0,0 +1,125 @@ +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 = Merge< + { + as?: As; + children: React.ReactNode; + className?: string; + elevation?: 1 | 2; + }, + React.ComponentProps +>; + +export const DropdownPopover = ({ + isOpen, + onClose, + reference, + popoverElement, + container, + placement, + offset = 4, + flip, + strategy, + matchReferenceWidth, + closeOnClickOutside, + children, + ...props +}: DropdownProps & Omit) => { + const popoverProps = { + isOpen, + onClose, + reference, + popoverElement, + container, + placement, + offset, + flip, + strategy, + matchReferenceWidth, + closeOnClickOutside, + }; + return ( + + {({ props: popoverChildProps }) => ( + + {children} + + )} + + ); +}; + +export const Dropdown = ({ + as: asComp, + children, + className, + elevation = 1, + ...props +}: DropdownProps) => { + const Component = asComp ?? 'div'; + return ( + + {children} + + ); +}; + +type DropdownItemProps = Merge< + { as?: As; children: React.ReactNode; className?: string; active?: boolean }, + React.ComponentPropsWithoutRef +>; + +export const DropdownItem = ({ + active, + as: AsComp, + children, + className, + ...props +}: DropdownItemProps) => { + const Component = AsComp ?? 'div'; + return ( + + {children} + + ); +}; + +export const DropdownItemButton: React.FC< + { icon?: IconProp } & React.ComponentProps<'button'> +> = ({ icon, children, className, ...props }) => { + return ( + + {icon && } + {children} + + ); +}; diff --git a/package.json b/package.json index 745f3ae721..921b2ea6d4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index c9f9d4f50f..eda8c8d9e7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -3737,6 +3738,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" From 9830f6d361dcc8c0c767c79d66cbef6793cb3071 Mon Sep 17 00:00:00 2001 From: Echo Date: Thu, 30 Jul 2026 14:26:42 +0200 Subject: [PATCH 2/6] Compose side fixes (#40000) --- .../mastodon/api_types/media_attachments.ts | 12 ++-- .../mastodon/components/autosuggest/utils.ts | 6 +- .../components/autosuggest_textarea.jsx | 4 +- .../mastodon/components/popover/index.tsx | 13 +++-- .../compose/components/language_dropdown.tsx | 10 ++-- .../mastodon/reducers/media_attachments.js | 4 +- app/javascript/mastodon/selectors/statuses.ts | 2 +- app/javascript/testing/api.ts | 56 ++++++++++++++++++- 8 files changed, 86 insertions(+), 21 deletions(-) diff --git a/app/javascript/mastodon/api_types/media_attachments.ts b/app/javascript/mastodon/api_types/media_attachments.ts index 6242569b82..8cb798f760 100644 --- a/app/javascript/mastodon/api_types/media_attachments.ts +++ b/app/javascript/mastodon/api_types/media_attachments.ts @@ -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; +} diff --git a/app/javascript/mastodon/components/autosuggest/utils.ts b/app/javascript/mastodon/components/autosuggest/utils.ts index 3e02114a97..99a433358f 100644 --- a/app/javascript/mastodon/components/autosuggest/utils.ts +++ b/app/javascript/mastodon/components/autosuggest/utils.ts @@ -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; } }; diff --git a/app/javascript/mastodon/components/autosuggest_textarea.jsx b/app/javascript/mastodon/components/autosuggest_textarea.jsx index ddf670c4cf..3e48d38b6c 100644 --- a/app/javascript/mastodon/components/autosuggest_textarea.jsx +++ b/app/javascript/mastodon/components/autosuggest_textarea.jsx @@ -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} ); - }; + }, [selectedSuggestion, handleSuggestionClick]); const handleRef = useCallback((element) => { textareaRef.current = element; diff --git a/app/javascript/mastodon/components/popover/index.tsx b/app/javascript/mastodon/components/popover/index.tsx index 5d7f84938d..dd7a8dfabf 100644 --- a/app/javascript/mastodon/components/popover/index.tsx +++ b/app/javascript/mastodon/components/popover/index.tsx @@ -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 & { - ref?: React.RefCallback; - style: React.CSSProperties; - }; + props: PopoverChildProps; }) => React.ReactNode; } +export interface PopoverChildProps { + ref?: React.RefCallback; + style: React.CSSProperties; + 'data-popover-placement': Placement; + 'data-popover-reference-hidden'?: boolean; + 'data-popover-escaped'?: boolean; +} + export const Popover: React.FC = ({ isOpen, onClose, diff --git a/app/javascript/mastodon/features/compose/components/language_dropdown.tsx b/app/javascript/mastodon/features/compose/components/language_dropdown.tsx index ebf577c058..2a07675a50 100644 --- a/app/javascript/mastodon/features/compose/components/language_dropdown.tsx +++ b/app/javascript/mastodon/features/compose/components/language_dropdown.tsx @@ -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(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) { diff --git a/app/javascript/mastodon/reducers/media_attachments.js b/app/javascript/mastodon/reducers/media_attachments.js index cbb4933bc7..650d13d924 100644 --- a/app/javascript/mastodon/reducers/media_attachments.js +++ b/app/javascript/mastodon/reducers/media_attachments.js @@ -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) { diff --git a/app/javascript/mastodon/selectors/statuses.ts b/app/javascript/mastodon/selectors/statuses.ts index 00ac0f3dd9..bbaf205f85 100644 --- a/app/javascript/mastodon/selectors/statuses.ts +++ b/app/javascript/mastodon/selectors/statuses.ts @@ -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; diff --git a/app/javascript/testing/api.ts b/app/javascript/testing/api.ts index ec75098d29..b8f9ccb3e0 100644 --- a/app/javascript/testing/api.ts +++ b/app/javascript/testing/api.ts @@ -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(); 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()]); From a1474e9316bfd91b791bb40f13259754cdfea161 Mon Sep 17 00:00:00 2001 From: Echo Date: Thu, 30 Jul 2026 15:15:33 +0200 Subject: [PATCH 3/6] Add maxWidth to Dropdown redesign (#40003) --- .../components/dropdown/redesign.module.scss | 1 - .../mastodon/components/dropdown/redesign.tsx | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/javascript/mastodon/components/dropdown/redesign.module.scss b/app/javascript/mastodon/components/dropdown/redesign.module.scss index 3b86410b34..1439df90f1 100644 --- a/app/javascript/mastodon/components/dropdown/redesign.module.scss +++ b/app/javascript/mastodon/components/dropdown/redesign.module.scss @@ -5,7 +5,6 @@ display: flex; flex-direction: column; - align-items: flex-start; padding: var(--space-2xs) 0; border-radius: var(--radius-md); background: var(--color-bg-primary); diff --git a/app/javascript/mastodon/components/dropdown/redesign.tsx b/app/javascript/mastodon/components/dropdown/redesign.tsx index afa3553c3c..3587c01d66 100644 --- a/app/javascript/mastodon/components/dropdown/redesign.tsx +++ b/app/javascript/mastodon/components/dropdown/redesign.tsx @@ -19,11 +19,13 @@ export type DropdownProps = Merge< children: React.ReactNode; className?: string; elevation?: 1 | 2; + maxWidth?: number | string; + style?: React.CSSProperties; }, React.ComponentProps >; -export const DropdownPopover = ({ +export const DropdownPopover = ({ isOpen, onClose, reference, @@ -62,11 +64,13 @@ export const DropdownPopover = ({ ); }; -export const Dropdown = ({ +export const Dropdown = ({ as: asComp, children, className, elevation = 1, + maxWidth, + style, ...props }: DropdownProps) => { const Component = asComp ?? 'div'; @@ -75,6 +79,10 @@ export const Dropdown = ({ {...props} className={classNames(className, classes.menu)} data-elevation={elevation} + style={{ + maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth, + ...style, + }} > {children} @@ -82,11 +90,11 @@ export const Dropdown = ({ }; type DropdownItemProps = Merge< - { as?: As; children: React.ReactNode; className?: string; active?: boolean }, + { as?: As; children?: React.ReactNode; className?: string; active?: boolean }, React.ComponentPropsWithoutRef >; -export const DropdownItem = ({ +export const DropdownItem = ({ active, as: AsComp, children, From cca2302f0dc64239d784cd935fa58a3b22693cbf Mon Sep 17 00:00:00 2001 From: Echo Date: Thu, 30 Jul 2026 12:15:10 +0200 Subject: [PATCH 4/6] [Glitch] Redesign dropdown Port c47bf15bd93ea857a4d98b0090a878d36593e1a7 to glitch-soc Signed-off-by: Claire --- .../components/dropdown/redesign.module.scss | 79 +++++++++++ .../components/dropdown/redesign.stories.tsx | 123 +++++++++++++++++ .../glitch/components/dropdown/redesign.tsx | 125 ++++++++++++++++++ 3 files changed, 327 insertions(+) create mode 100644 app/javascript/flavours/glitch/components/dropdown/redesign.module.scss create mode 100644 app/javascript/flavours/glitch/components/dropdown/redesign.stories.tsx create mode 100644 app/javascript/flavours/glitch/components/dropdown/redesign.tsx diff --git a/app/javascript/flavours/glitch/components/dropdown/redesign.module.scss b/app/javascript/flavours/glitch/components/dropdown/redesign.module.scss new file mode 100644 index 0000000000..3b86410b34 --- /dev/null +++ b/app/javascript/flavours/glitch/components/dropdown/redesign.module.scss @@ -0,0 +1,79 @@ +@use '@/styles/mastodon/mixins'; + +.menu { + @include mixins.elevation-1; + + display: flex; + flex-direction: column; + align-items: flex-start; + 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))); +} diff --git a/app/javascript/flavours/glitch/components/dropdown/redesign.stories.tsx b/app/javascript/flavours/glitch/components/dropdown/redesign.stories.tsx new file mode 100644 index 0000000000..9f89d9e1df --- /dev/null +++ b/app/javascript/flavours/glitch/components/dropdown/redesign.stories.tsx @@ -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, 'children'>>; + +export default meta; + +type Story = StoryObj; + +const handleMenuItemClick = action('menu item click'); + +export const Simple: Story = { + render(args) { + return ( + + + First item + + + Second item + + + ); + }, +}; + +export const Popover: Story = { + render(args) { + const [ref, setRef] = useState(null); + const [open, { onToggle, onFalse }] = useToggle(); + + return ( +
+ + + + + First item + + + Second item + + +
+ ); + }, +}; + +export const Controls: Story = { + render(args) { + const [sun, { onToggle }] = useToggle(); + return ( + + + First item + + +
+ + + {sun ? ( + + ) : ( + + )} + + +
+ ); + }, +}; diff --git a/app/javascript/flavours/glitch/components/dropdown/redesign.tsx b/app/javascript/flavours/glitch/components/dropdown/redesign.tsx new file mode 100644 index 0000000000..afa3553c3c --- /dev/null +++ b/app/javascript/flavours/glitch/components/dropdown/redesign.tsx @@ -0,0 +1,125 @@ +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 = Merge< + { + as?: As; + children: React.ReactNode; + className?: string; + elevation?: 1 | 2; + }, + React.ComponentProps +>; + +export const DropdownPopover = ({ + isOpen, + onClose, + reference, + popoverElement, + container, + placement, + offset = 4, + flip, + strategy, + matchReferenceWidth, + closeOnClickOutside, + children, + ...props +}: DropdownProps & Omit) => { + const popoverProps = { + isOpen, + onClose, + reference, + popoverElement, + container, + placement, + offset, + flip, + strategy, + matchReferenceWidth, + closeOnClickOutside, + }; + return ( + + {({ props: popoverChildProps }) => ( + + {children} + + )} + + ); +}; + +export const Dropdown = ({ + as: asComp, + children, + className, + elevation = 1, + ...props +}: DropdownProps) => { + const Component = asComp ?? 'div'; + return ( + + {children} + + ); +}; + +type DropdownItemProps = Merge< + { as?: As; children: React.ReactNode; className?: string; active?: boolean }, + React.ComponentPropsWithoutRef +>; + +export const DropdownItem = ({ + active, + as: AsComp, + children, + className, + ...props +}: DropdownItemProps) => { + const Component = AsComp ?? 'div'; + return ( + + {children} + + ); +}; + +export const DropdownItemButton: React.FC< + { icon?: IconProp } & React.ComponentProps<'button'> +> = ({ icon, children, className, ...props }) => { + return ( + + {icon && } + {children} + + ); +}; From 29bc6781412171a011796a0cd09a7de51b602b41 Mon Sep 17 00:00:00 2001 From: Echo Date: Thu, 30 Jul 2026 14:26:42 +0200 Subject: [PATCH 5/6] [Glitch] Compose side fixes Port 9830f6d361dcc8c0c767c79d66cbef6793cb3071 to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/api_types/media_attachments.ts | 12 ++++++++---- .../flavours/glitch/components/autosuggest/utils.ts | 6 +++--- .../glitch/components/autosuggest_textarea.jsx | 4 ++-- .../flavours/glitch/components/popover/index.tsx | 13 +++++++++---- .../compose/components/language_dropdown.tsx | 10 ++++++---- .../flavours/glitch/reducers/media_attachments.js | 4 ++-- .../flavours/glitch/selectors/statuses.ts | 2 +- 7 files changed, 31 insertions(+), 20 deletions(-) diff --git a/app/javascript/flavours/glitch/api_types/media_attachments.ts b/app/javascript/flavours/glitch/api_types/media_attachments.ts index 6242569b82..8cb798f760 100644 --- a/app/javascript/flavours/glitch/api_types/media_attachments.ts +++ b/app/javascript/flavours/glitch/api_types/media_attachments.ts @@ -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; +} diff --git a/app/javascript/flavours/glitch/components/autosuggest/utils.ts b/app/javascript/flavours/glitch/components/autosuggest/utils.ts index 3e02114a97..99a433358f 100644 --- a/app/javascript/flavours/glitch/components/autosuggest/utils.ts +++ b/app/javascript/flavours/glitch/components/autosuggest/utils.ts @@ -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; } }; diff --git a/app/javascript/flavours/glitch/components/autosuggest_textarea.jsx b/app/javascript/flavours/glitch/components/autosuggest_textarea.jsx index ddf670c4cf..3e48d38b6c 100644 --- a/app/javascript/flavours/glitch/components/autosuggest_textarea.jsx +++ b/app/javascript/flavours/glitch/components/autosuggest_textarea.jsx @@ -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} ); - }; + }, [selectedSuggestion, handleSuggestionClick]); const handleRef = useCallback((element) => { textareaRef.current = element; diff --git a/app/javascript/flavours/glitch/components/popover/index.tsx b/app/javascript/flavours/glitch/components/popover/index.tsx index 7e42ed13b6..3e325ea02e 100644 --- a/app/javascript/flavours/glitch/components/popover/index.tsx +++ b/app/javascript/flavours/glitch/components/popover/index.tsx @@ -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 & { - ref?: React.RefCallback; - style: React.CSSProperties; - }; + props: PopoverChildProps; }) => React.ReactNode; } +export interface PopoverChildProps { + ref?: React.RefCallback; + style: React.CSSProperties; + 'data-popover-placement': Placement; + 'data-popover-reference-hidden'?: boolean; + 'data-popover-escaped'?: boolean; +} + export const Popover: React.FC = ({ isOpen, onClose, diff --git a/app/javascript/flavours/glitch/features/compose/components/language_dropdown.tsx b/app/javascript/flavours/glitch/features/compose/components/language_dropdown.tsx index 8ddd65c4a3..589873cfa0 100644 --- a/app/javascript/flavours/glitch/features/compose/components/language_dropdown.tsx +++ b/app/javascript/flavours/glitch/features/compose/components/language_dropdown.tsx @@ -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(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) { diff --git a/app/javascript/flavours/glitch/reducers/media_attachments.js b/app/javascript/flavours/glitch/reducers/media_attachments.js index cbb4933bc7..650d13d924 100644 --- a/app/javascript/flavours/glitch/reducers/media_attachments.js +++ b/app/javascript/flavours/glitch/reducers/media_attachments.js @@ -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) { diff --git a/app/javascript/flavours/glitch/selectors/statuses.ts b/app/javascript/flavours/glitch/selectors/statuses.ts index f385d2532e..0acbd626cc 100644 --- a/app/javascript/flavours/glitch/selectors/statuses.ts +++ b/app/javascript/flavours/glitch/selectors/statuses.ts @@ -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; From 4a02ccc2aa668c008da15721c046a0602340bca0 Mon Sep 17 00:00:00 2001 From: Echo Date: Thu, 30 Jul 2026 15:15:33 +0200 Subject: [PATCH 6/6] [Glitch] Add maxWidth to Dropdown redesign Port a1474e9316bfd91b791bb40f13259754cdfea161 to glitch-soc Signed-off-by: Claire --- .../components/dropdown/redesign.module.scss | 1 - .../glitch/components/dropdown/redesign.tsx | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/javascript/flavours/glitch/components/dropdown/redesign.module.scss b/app/javascript/flavours/glitch/components/dropdown/redesign.module.scss index 3b86410b34..1439df90f1 100644 --- a/app/javascript/flavours/glitch/components/dropdown/redesign.module.scss +++ b/app/javascript/flavours/glitch/components/dropdown/redesign.module.scss @@ -5,7 +5,6 @@ display: flex; flex-direction: column; - align-items: flex-start; padding: var(--space-2xs) 0; border-radius: var(--radius-md); background: var(--color-bg-primary); diff --git a/app/javascript/flavours/glitch/components/dropdown/redesign.tsx b/app/javascript/flavours/glitch/components/dropdown/redesign.tsx index afa3553c3c..3587c01d66 100644 --- a/app/javascript/flavours/glitch/components/dropdown/redesign.tsx +++ b/app/javascript/flavours/glitch/components/dropdown/redesign.tsx @@ -19,11 +19,13 @@ export type DropdownProps = Merge< children: React.ReactNode; className?: string; elevation?: 1 | 2; + maxWidth?: number | string; + style?: React.CSSProperties; }, React.ComponentProps >; -export const DropdownPopover = ({ +export const DropdownPopover = ({ isOpen, onClose, reference, @@ -62,11 +64,13 @@ export const DropdownPopover = ({ ); }; -export const Dropdown = ({ +export const Dropdown = ({ as: asComp, children, className, elevation = 1, + maxWidth, + style, ...props }: DropdownProps) => { const Component = asComp ?? 'div'; @@ -75,6 +79,10 @@ export const Dropdown = ({ {...props} className={classNames(className, classes.menu)} data-elevation={elevation} + style={{ + maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth, + ...style, + }} > {children} @@ -82,11 +90,11 @@ export const Dropdown = ({ }; type DropdownItemProps = Merge< - { as?: As; children: React.ReactNode; className?: string; active?: boolean }, + { as?: As; children?: React.ReactNode; className?: string; active?: boolean }, React.ComponentPropsWithoutRef >; -export const DropdownItem = ({ +export const DropdownItem = ({ active, as: AsComp, children,