A super tab idea
This commit is contained in:
parent
d9c0366219
commit
db995addae
8 changed files with 152 additions and 86 deletions
|
@ -781,17 +781,6 @@ Signal Desktop makes use of the following open source projects.
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
## focusable-selectors
|
||||
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2021 Kitty Giraudel
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
## form-data
|
||||
|
||||
Copyright (c) 2012 Felix Geisendörfer (felix@debuggable.com) and contributors
|
||||
|
|
|
@ -114,7 +114,6 @@
|
|||
"filesize": "3.6.1",
|
||||
"firstline": "1.2.1",
|
||||
"focus-trap-react": "8.8.1",
|
||||
"focusable-selectors": "0.8.0",
|
||||
"form-data": "4.0.0",
|
||||
"fs-extra": "5.0.0",
|
||||
"fuse.js": "6.5.3",
|
||||
|
|
|
@ -191,6 +191,7 @@ import { RetryPlaceholders } from './util/retryPlaceholders';
|
|||
import { setBatchingStrategy } from './util/messageBatcher';
|
||||
import { parseRemoteClientExpiration } from './util/parseRemoteClientExpiration';
|
||||
import { makeLookup } from './util/makeLookup';
|
||||
import { focusableSelectors } from './util/focusableSelectors';
|
||||
|
||||
export function isOverHourIntoPast(timestamp: number): boolean {
|
||||
const HOUR = 1000 * 60 * 60;
|
||||
|
@ -1352,6 +1353,52 @@ export async function startApp(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
// Super tab :)
|
||||
if (commandOrCtrl && key === 'F6') {
|
||||
window.enterKeyboardMode();
|
||||
const focusedElement = document.activeElement;
|
||||
const targets: Array<HTMLElement> = Array.from(
|
||||
document.querySelectorAll('[data-supertab="true"]')
|
||||
);
|
||||
|
||||
const focusedIndex = targets.findIndex(target => {
|
||||
if (!target || !focusedElement) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target === focusedElement) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target.contains(focusedElement)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
const lastIndex = targets.length - 1;
|
||||
const increment = shiftKey ? -1 : 1;
|
||||
|
||||
let index;
|
||||
if (focusedIndex < 0 || focusedIndex >= lastIndex) {
|
||||
index = 0;
|
||||
} else {
|
||||
index = focusedIndex + increment;
|
||||
}
|
||||
|
||||
while (!targets[index]) {
|
||||
index += increment;
|
||||
if (index > lastIndex || index < 0) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
targets[index]
|
||||
.querySelectorAll<HTMLElement>(focusableSelectors.join(','))[0]
|
||||
?.focus();
|
||||
}
|
||||
|
||||
// Navigate by section
|
||||
if (commandOrCtrl && !shiftKey && (key === 't' || key === 'T')) {
|
||||
window.enterKeyboardMode();
|
||||
|
|
|
@ -96,76 +96,82 @@ export function CustomColorEditor({
|
|||
includeAnotherBubble
|
||||
/>
|
||||
{selectedTab === TabViews.Gradient && (
|
||||
<GradientDial
|
||||
deg={color.deg}
|
||||
knob1Style={{ backgroundColor: getHSL(color.start) }}
|
||||
knob2Style={{
|
||||
backgroundColor: getHSL(color.end || ULTRAMARINE_ISH_VALUES),
|
||||
}}
|
||||
onChange={deg => {
|
||||
setColor({
|
||||
...color,
|
||||
deg,
|
||||
});
|
||||
}}
|
||||
onClick={knob => setSelectedColorKnob(knob)}
|
||||
selectedKnob={selectedColorKnob}
|
||||
/>
|
||||
<div data-supertab>
|
||||
<GradientDial
|
||||
deg={color.deg}
|
||||
knob1Style={{ backgroundColor: getHSL(color.start) }}
|
||||
knob2Style={{
|
||||
backgroundColor: getHSL(
|
||||
color.end || ULTRAMARINE_ISH_VALUES
|
||||
),
|
||||
}}
|
||||
onChange={deg => {
|
||||
setColor({
|
||||
...color,
|
||||
deg,
|
||||
});
|
||||
}}
|
||||
onClick={knob => setSelectedColorKnob(knob)}
|
||||
selectedKnob={selectedColorKnob}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="CustomColorEditor__slider-container">
|
||||
{i18n('icu:CustomColorEditor__hue')}
|
||||
<Slider
|
||||
handleStyle={{
|
||||
backgroundColor: getHSL({
|
||||
hue,
|
||||
saturation: 100,
|
||||
}),
|
||||
}}
|
||||
label={i18n('icu:CustomColorEditor__hue')}
|
||||
moduleClassName="CustomColorEditor__hue-slider"
|
||||
onChange={(percentage: number) => {
|
||||
setColor({
|
||||
...color,
|
||||
[selectedColorKnob]: {
|
||||
...ULTRAMARINE_ISH_VALUES,
|
||||
...color[selectedColorKnob],
|
||||
hue: getValue(percentage, MAX_HUE),
|
||||
},
|
||||
});
|
||||
}}
|
||||
value={getPercentage(hue, MAX_HUE)}
|
||||
/>
|
||||
<div data-supertab>
|
||||
<div className="CustomColorEditor__slider-container">
|
||||
{i18n('icu:CustomColorEditor__hue')}
|
||||
<Slider
|
||||
handleStyle={{
|
||||
backgroundColor: getHSL({
|
||||
hue,
|
||||
saturation: 100,
|
||||
}),
|
||||
}}
|
||||
label={i18n('icu:CustomColorEditor__hue')}
|
||||
moduleClassName="CustomColorEditor__hue-slider"
|
||||
onChange={(percentage: number) => {
|
||||
setColor({
|
||||
...color,
|
||||
[selectedColorKnob]: {
|
||||
...ULTRAMARINE_ISH_VALUES,
|
||||
...color[selectedColorKnob],
|
||||
hue: getValue(percentage, MAX_HUE),
|
||||
},
|
||||
});
|
||||
}}
|
||||
value={getPercentage(hue, MAX_HUE)}
|
||||
/>
|
||||
</div>
|
||||
<div className="CustomColorEditor__slider-container">
|
||||
{i18n('icu:CustomColorEditor__saturation')}
|
||||
<Slider
|
||||
containerStyle={getCustomColorStyle({
|
||||
deg: 180,
|
||||
start: { hue, saturation: 0 },
|
||||
end: { hue, saturation: 100 },
|
||||
})}
|
||||
handleStyle={{
|
||||
backgroundColor: getHSL(
|
||||
color[selectedColorKnob] || ULTRAMARINE_ISH_VALUES
|
||||
),
|
||||
}}
|
||||
label={i18n('icu:CustomColorEditor__saturation')}
|
||||
moduleClassName="CustomColorEditor__saturation-slider"
|
||||
onChange={(value: number) => {
|
||||
setColor({
|
||||
...color,
|
||||
[selectedColorKnob]: {
|
||||
...ULTRAMARINE_ISH_VALUES,
|
||||
...color[selectedColorKnob],
|
||||
saturation: value,
|
||||
},
|
||||
});
|
||||
}}
|
||||
value={saturation}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="CustomColorEditor__slider-container">
|
||||
{i18n('icu:CustomColorEditor__saturation')}
|
||||
<Slider
|
||||
containerStyle={getCustomColorStyle({
|
||||
deg: 180,
|
||||
start: { hue, saturation: 0 },
|
||||
end: { hue, saturation: 100 },
|
||||
})}
|
||||
handleStyle={{
|
||||
backgroundColor: getHSL(
|
||||
color[selectedColorKnob] || ULTRAMARINE_ISH_VALUES
|
||||
),
|
||||
}}
|
||||
label={i18n('icu:CustomColorEditor__saturation')}
|
||||
moduleClassName="CustomColorEditor__saturation-slider"
|
||||
onChange={(value: number) => {
|
||||
setColor({
|
||||
...color,
|
||||
[selectedColorKnob]: {
|
||||
...ULTRAMARINE_ISH_VALUES,
|
||||
...color[selectedColorKnob],
|
||||
saturation: value,
|
||||
},
|
||||
});
|
||||
}}
|
||||
value={saturation}
|
||||
/>
|
||||
</div>
|
||||
<div className="CustomColorEditor__footer">
|
||||
<div className="CustomColorEditor__footer" data-supertab>
|
||||
<Button variant={ButtonVariant.Secondary} onClick={onClose}>
|
||||
{i18n('icu:cancel')}
|
||||
</Button>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
import type { AudioDevice } from '@signalapp/ringrtc';
|
||||
import type { ReactNode } from 'react';
|
||||
import focusableSelectors from 'focusable-selectors';
|
||||
import React, {
|
||||
useCallback,
|
||||
useEffect,
|
||||
|
@ -59,6 +58,7 @@ import { DurationInSeconds } from '../util/durations';
|
|||
import { useEscapeHandling } from '../hooks/useEscapeHandling';
|
||||
import { useUniqueId } from '../hooks/useUniqueId';
|
||||
import { useTheme } from '../hooks/useTheme';
|
||||
import { focusableSelectors } from '../util/focusableSelectors';
|
||||
|
||||
type CheckboxChangeHandlerType = (value: boolean) => unknown;
|
||||
type SelectChangeHandlerType<T = string | number> = (value: T) => unknown;
|
||||
|
|
|
@ -63,7 +63,7 @@ export function useTabs(options: TabsOptionsType): TabsProps {
|
|||
}
|
||||
|
||||
const tabsHeaderElement = (
|
||||
<div className={getClassName('')}>
|
||||
<div className={getClassName('')} data-supertab>
|
||||
{options.tabs.map(({ id, label }) => (
|
||||
<div
|
||||
className={classNames(
|
||||
|
|
30
ts/util/focusableSelectors.ts
Normal file
30
ts/util/focusableSelectors.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
// https://www.npmjs.com/package/focusable-selectors
|
||||
// https://github.com/KittyGiraudel/focusable-selectors/issues/15
|
||||
|
||||
const not = {
|
||||
inert: ':not([inert]):not([inert] *)',
|
||||
negTabIndex: ':not([tabindex^="-"])',
|
||||
disabled: ':not(:disabled)',
|
||||
};
|
||||
|
||||
export const focusableSelectors = [
|
||||
`a[href]${not.inert}${not.negTabIndex}`,
|
||||
`area[href]${not.inert}${not.negTabIndex}`,
|
||||
`input:not([type="hidden"]):not([type="radio"])${not.inert}${not.negTabIndex}${not.disabled}`,
|
||||
`input[type="radio"]${not.inert}${not.negTabIndex}${not.disabled}`,
|
||||
`select${not.inert}${not.negTabIndex}${not.disabled}`,
|
||||
`textarea${not.inert}${not.negTabIndex}${not.disabled}`,
|
||||
`button${not.inert}${not.negTabIndex}${not.disabled}`,
|
||||
`details${not.inert} > summary:first-of-type${not.negTabIndex}`,
|
||||
// Discard until Firefox supports `:has()`
|
||||
// See: https://github.com/KittyGiraudel/focusable-selectors/issues/12
|
||||
// `details:not(:has(> summary))${not.inert}${not.negTabIndex}`,
|
||||
`iframe${not.inert}${not.negTabIndex}`,
|
||||
`audio[controls]${not.inert}${not.negTabIndex}`,
|
||||
`video[controls]${not.inert}${not.negTabIndex}`,
|
||||
`[contenteditable]${not.inert}${not.negTabIndex}`,
|
||||
`[tabindex]${not.inert}${not.negTabIndex}`,
|
||||
];
|
|
@ -9488,11 +9488,6 @@ focus-trap@^6.7.1:
|
|||
dependencies:
|
||||
tabbable "^5.2.1"
|
||||
|
||||
focusable-selectors@0.8.0:
|
||||
version "0.8.0"
|
||||
resolved "https://registry.yarnpkg.com/focusable-selectors/-/focusable-selectors-0.8.0.tgz#aecfd7ce2ac369fd808289d4bcf474ac2bf03562"
|
||||
integrity sha512-lKyq/Cth8mTEzJk2CLHLdMDYl2zmMicQflfrUMs0CZ3Boc5Ca/63d7z+GgKV3nKm79KqrPtCWrwTdoV9RTjVCA==
|
||||
|
||||
follow-redirects@^1.0.0:
|
||||
version "1.14.9"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
|
||||
|
|
Loading…
Reference in a new issue