mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-03 03:40:23 +03:00
[DOP-3497]: Refactor state
This commit is contained in:
parent
47d266f8a8
commit
207c3a9780
4
.npmrc
4
.npmrc
|
@ -1,5 +1,5 @@
|
||||||
registry=https://artifactory.corp.mongodb.com/artifactory/api/npm/npm/
|
registry=https://artifactory.corp.mongodb.com/artifactory/api/npm/npm/
|
||||||
_auth=${NPM_BASE_64_AUTH}
|
_email=docs-platform
|
||||||
_email=${NPM_EMAIL}
|
|
||||||
_always-auth=true
|
_always-auth=true
|
||||||
git-tag-version=false
|
git-tag-version=false
|
||||||
|
//artifactory.corp.mongodb.com/artifactory/api/npm/npm/:_auth=ZG9jcy1wbGF0Zm9ybTpBS0NwOGpSYkRUVjRVRktUM0JSTndlckxrckwyVFdjaDZ4U0d0c3JKZUhyRmtFTExGdFZDNDVnZEMxRGF4ZzZ5ckhNeWt2U0Zv
|
||||||
|
|
21537
package-lock.json
generated
21537
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -32,6 +32,7 @@
|
||||||
"start": "webpack serve --mode=development --env playground --hot --config demo/webpack.config.ts",
|
"start": "webpack serve --mode=development --env playground --hot --config demo/webpack.config.ts",
|
||||||
"start:prod": "webpack serve --env playground --mode=production --config demo/webpack.config.ts",
|
"start:prod": "webpack serve --env playground --mode=production --config demo/webpack.config.ts",
|
||||||
"start:benchmark": "webpack serve --mode=production --env.bench --config demo/webpack.config.ts",
|
"start:benchmark": "webpack serve --mode=production --env.bench --config demo/webpack.config.ts",
|
||||||
|
"dev:vite": "vite",
|
||||||
"test": "npm run unit && npm run license-check",
|
"test": "npm run unit && npm run license-check",
|
||||||
"unit": "jest --coverage",
|
"unit": "jest --coverage",
|
||||||
"test:update-snapshot": "jest --updateSnapshot",
|
"test:update-snapshot": "jest --updateSnapshot",
|
||||||
|
@ -76,7 +77,7 @@
|
||||||
"@types/lunr": "^2.3.3",
|
"@types/lunr": "^2.3.3",
|
||||||
"@types/mark.js": "^8.11.5",
|
"@types/mark.js": "^8.11.5",
|
||||||
"@types/marked": "^4.0.3",
|
"@types/marked": "^4.0.3",
|
||||||
"@types/node": "^15.6.1",
|
"@types/node": "^15.14.9",
|
||||||
"@types/prismjs": "^1.16.5",
|
"@types/prismjs": "^1.16.5",
|
||||||
"@types/prop-types": "^15.7.3",
|
"@types/prop-types": "^15.7.3",
|
||||||
"@types/react": "^17.0.8",
|
"@types/react": "^17.0.8",
|
||||||
|
@ -151,6 +152,7 @@
|
||||||
"@mdb/flora": "^0.20.5",
|
"@mdb/flora": "^0.20.5",
|
||||||
"@mdx-js/react": "^1.6.22",
|
"@mdx-js/react": "^1.6.22",
|
||||||
"@redocly/openapi-core": "^1.0.0-beta.104",
|
"@redocly/openapi-core": "^1.0.0-beta.104",
|
||||||
|
"@vitejs/plugin-react": "^3.1.0",
|
||||||
"classnames": "^2.3.1",
|
"classnames": "^2.3.1",
|
||||||
"decko": "^1.2.0",
|
"decko": "^1.2.0",
|
||||||
"dompurify": "^2.2.8",
|
"dompurify": "^2.2.8",
|
||||||
|
@ -172,7 +174,8 @@
|
||||||
"style-loader": "^3.3.1",
|
"style-loader": "^3.3.1",
|
||||||
"swagger2openapi": "^7.0.6",
|
"swagger2openapi": "^7.0.6",
|
||||||
"theme-ui": "^0.13.1",
|
"theme-ui": "^0.13.1",
|
||||||
"url-template": "^2.0.8"
|
"url-template": "^2.0.8",
|
||||||
|
"vite": "^4.1.1"
|
||||||
},
|
},
|
||||||
"size-limit": [
|
"size-limit": [
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,18 +3,19 @@ import { StyledLi, StyledOptionText, StyledPlaceholder } from './styled.elements
|
||||||
import Checkmark from './CheckmarkSvg';
|
import Checkmark from './CheckmarkSvg';
|
||||||
import { OptionProps } from './types';
|
import { OptionProps } from './types';
|
||||||
|
|
||||||
export const Option = ({ option, selected, onClick }: OptionProps) => {
|
export const Option = ({ option, selected, onClick, focused }: OptionProps) => {
|
||||||
const KEY_ENTER = 'ENTER';
|
const KEY_ENTER = 'ENTER';
|
||||||
const KEY_SPACE = 'SPACE';
|
const KEY_SPACE = 'SPACE';
|
||||||
|
|
||||||
const handleKeyPress = (event: React.KeyboardEvent) => {
|
const handleKeyPress = (event: React.KeyboardEvent) => {
|
||||||
|
console.log(event.key);
|
||||||
if (event.key === KEY_ENTER || event.key === KEY_SPACE) {
|
if (event.key === KEY_ENTER || event.key === KEY_SPACE) {
|
||||||
onClick();
|
onClick();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledLi onClick={onClick} onKeyPress={handleKeyPress} selected={selected}>
|
<StyledLi onClick={onClick} onKeyPress={handleKeyPress} selected={selected} focused={focused}>
|
||||||
{selected ? <Checkmark /> : <StyledPlaceholder />}
|
{selected ? <Checkmark /> : <StyledPlaceholder />}
|
||||||
<StyledOptionText>{option}</StyledOptionText>
|
<StyledOptionText>{option}</StyledOptionText>
|
||||||
</StyledLi>
|
</StyledLi>
|
||||||
|
|
|
@ -24,8 +24,23 @@ const VersionSelectorComponent = ({
|
||||||
}: VersionSelectorProps): JSX.Element => {
|
}: VersionSelectorProps): JSX.Element => {
|
||||||
const initialSelectedIdx = resourceVersions.indexOf(active.resourceVersion);
|
const initialSelectedIdx = resourceVersions.indexOf(active.resourceVersion);
|
||||||
const [open, setOpen] = React.useState<boolean>(false);
|
const [open, setOpen] = React.useState<boolean>(false);
|
||||||
|
const [focusedIdx, setFocusedIdx] = React.useState<number | null>(null);
|
||||||
const [selectedIdx, setSelectedIdx] = React.useState<number>(initialSelectedIdx);
|
const [selectedIdx, setSelectedIdx] = React.useState<number>(initialSelectedIdx);
|
||||||
|
|
||||||
const menuListRef = React.useRef(null);
|
const menuListRef = React.useRef(null);
|
||||||
|
|
||||||
|
const options = resourceVersions.map((option, i) => {
|
||||||
|
return (
|
||||||
|
<Option
|
||||||
|
key={`option-${i}`}
|
||||||
|
selected={i === selectedIdx}
|
||||||
|
focused={i === focusedIdx && focusedIdx !== selectedIdx}
|
||||||
|
option={option}
|
||||||
|
onClick={() => handleClick(i)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
useOutsideClick(menuListRef, () => {
|
useOutsideClick(menuListRef, () => {
|
||||||
if (open) setOpen(false);
|
if (open) setOpen(false);
|
||||||
});
|
});
|
||||||
|
@ -35,6 +50,10 @@ const VersionSelectorComponent = ({
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleFocusChange = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
||||||
|
console.log(event.key);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledWrapper ref={menuListRef}>
|
<StyledWrapper ref={menuListRef}>
|
||||||
<StyledSelectWrapper>
|
<StyledSelectWrapper>
|
||||||
|
@ -50,18 +69,9 @@ const VersionSelectorComponent = ({
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
</StyledSelectWrapper>
|
</StyledSelectWrapper>
|
||||||
|
|
||||||
<StyledDropdown open={open}>
|
<StyledDropdown open={open} onKeyDown={handleFocusChange}>
|
||||||
<div>
|
<div>
|
||||||
<StyledMenuList>
|
<StyledMenuList>{options}</StyledMenuList>
|
||||||
{resourceVersions.map((option, i) => (
|
|
||||||
<Option
|
|
||||||
key={`option-${i}`}
|
|
||||||
selected={i === selectedIdx}
|
|
||||||
option={option}
|
|
||||||
onClick={() => handleClick(i)}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</StyledMenuList>
|
|
||||||
</div>
|
</div>
|
||||||
</StyledDropdown>
|
</StyledDropdown>
|
||||||
</StyledWrapper>
|
</StyledWrapper>
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { CSSProperties } from 'react';
|
||||||
|
|
||||||
export interface ActiveVersionData {
|
export interface ActiveVersionData {
|
||||||
resourceVersion: string;
|
resourceVersion: string;
|
||||||
apiVersion: string;
|
apiVersion: string;
|
||||||
|
@ -13,6 +15,7 @@ export interface OptionProps {
|
||||||
option: string;
|
option: string;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
|
focused: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ArrowIconProps {
|
export interface ArrowIconProps {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user