Skip to content

Commit 139dbf6

Browse files
authored
add ability to maximize code browser, other tweaks (#2403)
1 parent 8dca2e4 commit 139dbf6

7 files changed

Lines changed: 475 additions & 218 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
- Use the [template](#new-library-entry-template) as a guide.
3535
- Submit a PR.
3636

37+
> [!TIP]
38+
> You can also use the React Native Directory CLI to submit a library directly from the terminal. Run `bunx rn-directory submit` from the package root folder.
39+
> - https://github.com/Simek/rn-directory
40+
3741
### New library entry template
3842

3943
> [!IMPORTANT]

components/Icons/index.tsx

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,3 +1639,81 @@ export function FileMetadataIcon({ width = 24, height = 24, style }: IconProps)
16391639
</Svg>
16401640
);
16411641
}
1642+
1643+
export function MaximizeIcon({ width = 24, height = 24, style }: IconProps) {
1644+
return (
1645+
<Svg width={width} height={height} viewBox="0 0 256 256" style={style}>
1646+
<polyline
1647+
points="168 48 208 48 208 88"
1648+
fill="none"
1649+
stroke="currentColor"
1650+
strokeLinecap="round"
1651+
strokeLinejoin="round"
1652+
strokeWidth="16"
1653+
/>
1654+
<polyline
1655+
points="88 208 48 208 48 168"
1656+
fill="none"
1657+
stroke="currentColor"
1658+
strokeLinecap="round"
1659+
strokeLinejoin="round"
1660+
strokeWidth="16"
1661+
/>
1662+
<polyline
1663+
points="208 168 208 208 168 208"
1664+
fill="none"
1665+
stroke="currentColor"
1666+
strokeLinecap="round"
1667+
strokeLinejoin="round"
1668+
strokeWidth="16"
1669+
/>
1670+
<polyline
1671+
points="48 88 48 48 88 48"
1672+
fill="none"
1673+
stroke="currentColor"
1674+
strokeLinecap="round"
1675+
strokeLinejoin="round"
1676+
strokeWidth="16"
1677+
/>
1678+
</Svg>
1679+
);
1680+
}
1681+
1682+
export function MinimizeIcon({ width = 24, height = 24, style }: IconProps) {
1683+
return (
1684+
<Svg width={width} height={height} viewBox="0 0 256 256" style={style}>
1685+
<polyline
1686+
points="208 96 160 96 160 48"
1687+
fill="none"
1688+
stroke="currentColor"
1689+
strokeLinecap="round"
1690+
strokeLinejoin="round"
1691+
strokeWidth="16"
1692+
/>
1693+
<polyline
1694+
points="48 160 96 160 96 208"
1695+
fill="none"
1696+
stroke="currentColor"
1697+
strokeLinecap="round"
1698+
strokeLinejoin="round"
1699+
strokeWidth="16"
1700+
/>
1701+
<polyline
1702+
points="160 208 160 160 208 160"
1703+
fill="none"
1704+
stroke="currentColor"
1705+
strokeLinecap="round"
1706+
strokeLinejoin="round"
1707+
strokeWidth="16"
1708+
/>
1709+
<polyline
1710+
points="96 48 96 96 48 96"
1711+
fill="none"
1712+
stroke="currentColor"
1713+
strokeLinecap="round"
1714+
strokeLinejoin="round"
1715+
strokeWidth="16"
1716+
/>
1717+
</Svg>
1718+
);
1719+
}

components/InputKeyHint.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function InputKeyHint({ content }: Props) {
1414
return (
1515
<Label
1616
key={`key-${entry.key}`}
17-
style={tw`min-w-6 rounded-[3px] bg-palette-gray5 px-1 py-[3px] text-center tracking-[0.75px] text-tertiary dark:bg-powder dark:text-secondary`}>
17+
style={tw`font-mono min-w-6 rounded-[3px] bg-palette-gray5 px-1 py-[3px] text-center tracking-[0.25px] text-tertiary dark:bg-powder dark:text-secondary`}>
1818
{entry.key}
1919
</Label>
2020
);

components/Package/CodeBrowser/CodeBrowserContent.tsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,24 @@ import tw from '~/util/tailwind';
2020
import CodeBrowserContentFooter from './CodeBrowserContentFooter';
2121
import CodeBrowserContentHeader from './CodeBrowserContentHeader';
2222
import CodeBrowserContentHighlighter from './CodeBrowserContentHighlighter';
23+
import DisplayModeButton from './DisplayModeButton';
2324
import DownloadFileButton from './DownloadFileButton';
2425

2526
type Props = {
2627
packageName: string;
28+
isBrowserMaximized: boolean;
29+
toggleMaximized: () => void;
2730
filePath: string;
2831
fileData?: UnpkgMeta['files'][number];
2932
};
3033

31-
export default function CodeBrowserContent({ packageName, filePath, fileData }: Props) {
34+
export default function CodeBrowserContent({
35+
packageName,
36+
isBrowserMaximized,
37+
toggleMaximized,
38+
filePath,
39+
fileData,
40+
}: Props) {
3241
const [rawPreview, setRawPreview] = useState(false);
3342
const [imageData, setImageData] = useState<
3443
SyntheticEvent<HTMLImageElement>['currentTarget'] | null
@@ -64,7 +73,12 @@ export default function CodeBrowserContent({ packageName, filePath, fileData }:
6473
if (isLoading) {
6574
return (
6675
<>
67-
<CodeBrowserContentHeader filePath={filePath} />
76+
<CodeBrowserContentHeader filePath={filePath}>
77+
<DisplayModeButton
78+
isBrowserMaximized={isBrowserMaximized}
79+
toggleMaximized={toggleMaximized}
80+
/>
81+
</CodeBrowserContentHeader>
6882
<View style={tw`flex flex-1 items-center justify-center`}>
6983
<ThreeDotsLoader />
7084
</View>
@@ -103,6 +117,10 @@ export default function CodeBrowserContent({ packageName, filePath, fileData }:
103117
label="Copy"
104118
style={tw`relative right-0 top-0`}
105119
/>
120+
<DisplayModeButton
121+
isBrowserMaximized={isBrowserMaximized}
122+
toggleMaximized={toggleMaximized}
123+
/>
106124
</View>
107125
</CodeBrowserContentHeader>
108126
<CodeBrowserContentHighlighter
@@ -146,6 +164,10 @@ export default function CodeBrowserContent({ packageName, filePath, fileData }:
146164
{(isPreviewDisabled || isImageFile) && (
147165
<DownloadFileButton filePath={filePath} packageName={packageName} />
148166
)}
167+
<DisplayModeButton
168+
isBrowserMaximized={isBrowserMaximized}
169+
toggleMaximized={toggleMaximized}
170+
/>
149171
</View>
150172
</CodeBrowserContentHeader>
151173
<View style={tw`flex flex-1 items-center justify-center`}>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Pressable, View } from 'react-native';
2+
3+
import { useLayout } from '~/common/styleguide';
4+
import { MinimizeIcon } from '~/components/Icons';
5+
import InputKeyHint from '~/components/InputKeyHint';
6+
import Tooltip from '~/components/Tooltip';
7+
import tw from '~/util/tailwind';
8+
9+
type Props = {
10+
isBrowserMaximized: boolean;
11+
toggleMaximized: () => void;
12+
};
13+
14+
export default function DisplayModeButton({ isBrowserMaximized, toggleMaximized }: Props) {
15+
const { isSmallScreen } = useLayout();
16+
17+
const Icon = isBrowserMaximized ? MinimizeIcon : MinimizeIcon;
18+
19+
return (
20+
<Tooltip
21+
trigger={
22+
<Pressable onPress={toggleMaximized}>
23+
<Icon style={tw`size-5 text-palette-gray4 dark:text-pewter`} />
24+
</Pressable>
25+
}>
26+
{isBrowserMaximized ? (
27+
<View style={[tw`flex flex-row items-center gap-1.5`, !isSmallScreen && tw`-mr-1`]}>
28+
<span>Minimize code browser</span>
29+
{!isSmallScreen && <InputKeyHint content={[{ key: 'Esc' }]} />}
30+
</View>
31+
) : (
32+
'Maximize code browser'
33+
)}
34+
</Tooltip>
35+
);
36+
}

0 commit comments

Comments
 (0)