Skip to content

Commit 05153ca

Browse files
Pollepsjoepio
authored andcommitted
#228 Add icons to new route buttons + various styling improvements
1 parent 4943f8c commit 05153ca

File tree

13 files changed

+196
-103
lines changed

13 files changed

+196
-103
lines changed

data-browser/src/components/AtomicLink.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { FaExternalLinkAlt } from 'react-icons/fa';
66
import { ErrorLook } from '../components/ErrorLook';
77
import { isRunningInTauri } from '../helpers/tauri';
88

9-
export interface AtomicLinkProps {
9+
export interface AtomicLinkProps
10+
extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
1011
children?: ReactNode;
1112
/** An http URL to an Atomic Data resource, opened in this app and fetched as JSON-AD */
1213
subject?: string;
@@ -115,7 +116,6 @@ export const LinkView = styled.a<LinkViewProps>`
115116
pointer-events: ${props => (props.disabled ? 'none' : 'inherit')};
116117
117118
svg {
118-
margin-left: 0.3rem;
119119
font-size: 60%;
120120
}
121121
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
import { useSettings } from '../helpers/AppSettings';
4+
5+
const NAVBAR_HEIGHT = '2rem';
6+
const NAVBAR_CALC_PART = ` + ${NAVBAR_HEIGHT}`;
7+
8+
export interface NavBarSpacerProps {
9+
position: 'top' | 'bottom';
10+
baseMargin?: string;
11+
}
12+
13+
const size = (base = '0rem', withNav: boolean) =>
14+
`calc(${base}${withNav ? NAVBAR_CALC_PART : ''})`;
15+
16+
/** Makes room for the navbar when it is present at the given position. Animates its height. */
17+
export function NavBarSpacer({
18+
position,
19+
baseMargin,
20+
}: NavBarSpacerProps): JSX.Element {
21+
const { navbarFloating, navbarTop } = useSettings();
22+
23+
const getSize = () => {
24+
if (position === 'top') {
25+
return size(baseMargin, navbarTop);
26+
}
27+
28+
return size(baseMargin, !navbarFloating && !navbarTop);
29+
};
30+
31+
return <Spacing size={getSize()} />;
32+
}
33+
34+
interface SpacingProps {
35+
size: string;
36+
}
37+
38+
const Spacing = styled.div<SpacingProps>`
39+
height: ${p => p.size};
40+
transition: height 0.2s ease-out;
41+
`;

data-browser/src/components/Navigation.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import ResourceContextMenu from './ResourceContextMenu';
2121
import { isRunningInTauri } from '../helpers/tauri';
2222
import { shortcuts } from './HotKeyWrapper';
2323
import { MenuBarDropdownTrigger } from './ResourceContextMenu/MenuBarDropdownTrigger';
24+
import { NavBarSpacer } from './NavbarSpacer';
2425

2526
interface NavWrapperProps {
2627
children: React.ReactNode;
@@ -46,6 +47,7 @@ export function NavWrapper({ children }: NavWrapperProps): JSX.Element {
4647
navbarTop={navbarTop}
4748
navbarFloating={navbarFloating}
4849
>
50+
<NavBarSpacer position='top' />
4951
{children}
5052
</Content>
5153
</SideBarWrapper>
@@ -62,12 +64,7 @@ interface ContentProps {
6264
const Content = styled.div<ContentProps>`
6365
display: block;
6466
flex: 1;
65-
margin-top: ${props => (props.navbarTop ? '2rem' : '0')};
66-
margin-bottom: ${props =>
67-
props.navbarTop || props.navbarFloating ? '0' : '2rem'};
6867
overflow-y: auto;
69-
/* For smooth navbar position adjustments */
70-
transition: margin 0.2s;
7168
`;
7269

7370
/** Persistently shown navigation bar */

data-browser/src/components/NewInstanceButton/Base.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useStore } from '@tomic/react';
22
import React, { useCallback } from 'react';
33
import toast from 'react-hot-toast';
4+
import { IconType } from 'react-icons';
45
import { FaPlus } from 'react-icons/fa';
56
import { useNavigate } from 'react-router-dom';
67
import styled from 'styled-components';
@@ -12,6 +13,7 @@ export interface InstanceButtonBaseProps {
1213
subtle?: boolean;
1314
title: string;
1415
icon?: boolean;
16+
IconComponent?: IconType;
1517
label?: string;
1618
className?: string;
1719
}
@@ -22,6 +24,7 @@ export function Base({
2224
title,
2325
icon,
2426
onClick,
27+
IconComponent,
2528
label,
2629
className,
2730
}: React.PropsWithChildren<InstanceButtonBaseProps>): JSX.Element {
@@ -41,6 +44,8 @@ export function Base({
4144
onClick();
4245
}, [agent, navigate]);
4346

47+
const Icon = IconComponent ?? FaPlus;
48+
4449
return (
4550
<Button
4651
onClick={handleClick}
@@ -50,7 +55,7 @@ export function Base({
5055
>
5156
{icon ? (
5257
<IconWrapper>
53-
<FaPlus />
58+
<Icon />
5459
{label}
5560
</IconWrapper>
5661
) : (
@@ -64,5 +69,5 @@ export function Base({
6469
const IconWrapper = styled.div`
6570
display: flex;
6671
align-items: center;
67-
gap: 0.3rem;
72+
gap: 0.5rem;
6873
`;

data-browser/src/components/NewInstanceButton/NewBookmarkButton.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function NewBookmarkButton({
2626
klass,
2727
subtle,
2828
icon,
29+
IconComponent,
2930
parent,
3031
children,
3132
label,
@@ -60,6 +61,7 @@ export function NewBookmarkButton({
6061
onClick={show}
6162
title={title}
6263
icon={icon}
64+
IconComponent={IconComponent}
6365
subtle={subtle}
6466
label={label}
6567
>

data-browser/src/components/NewInstanceButton/NewFolderButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function NewFolderButton({
1818
klass,
1919
subtle,
2020
icon,
21+
IconComponent,
2122
parent,
2223
children,
2324
label,
@@ -49,6 +50,7 @@ export function NewFolderButton({
4950
onClick={show}
5051
title={title}
5152
icon={icon}
53+
IconComponent={IconComponent}
5254
subtle={subtle}
5355
label={label}
5456
>
@@ -60,7 +62,7 @@ export function NewFolderButton({
6062
</DialogTitle>
6163
<DialogContent>
6264
<form onSubmit={onDone}>
63-
<Field required label='url'>
65+
<Field required label='Name'>
6466
<InputWrapper>
6567
<InputStyled
6668
placeholder='New Folder'

data-browser/src/components/NewInstanceButton/NewInstanceButtonDefault.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function NewInstanceButtonDefault({
99
klass,
1010
subtle,
1111
icon,
12+
IconComponent,
1213
parent,
1314
children,
1415
label,
@@ -23,6 +24,7 @@ export function NewInstanceButtonDefault({
2324
<Base
2425
className={className}
2526
onClick={onClick}
27+
IconComponent={IconComponent}
2628
title={title}
2729
icon={icon}
2830
subtle={subtle}

data-browser/src/components/NewInstanceButton/NewInstanceButtonProps.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React from 'react';
2+
import { IconType } from 'react-icons';
23

34
interface Props {
45
/** URL of the Class to be instantiated */
56
klass: string;
67
subtle?: boolean;
78
icon?: boolean;
8-
/** ID of the parent Resource, which will be passed to the form */
9+
IconComponent?: IconType;
10+
/** subject of the parent Resource, which will be passed to the form */
911
parent?: string;
1012
/** Give explicit label. If missing, uses the Shortname of the Class */
1113
label?: string;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import styled from 'styled-components';
2+
import { AtomicLink } from '../AtomicLink';
3+
import { Logo } from '../Logo';
4+
import { SideBarHeader } from './SideBarHeader';
5+
import React from 'react';
6+
import { FaGithub, FaDiscord, FaBook } from 'react-icons/fa';
7+
8+
interface AboutItem {
9+
icon: React.ReactNode;
10+
helper: string;
11+
href: string;
12+
}
13+
14+
const aboutMenuItems: AboutItem[] = [
15+
{
16+
icon: <FaGithub />,
17+
helper: 'Github; View the source code for this application',
18+
href: 'https://github.com/atomicdata-dev/atomic-data-browser',
19+
},
20+
{
21+
icon: <FaDiscord />,
22+
helper: 'Discord; Chat with the Atomic Data community',
23+
href: 'https://discord.gg/a72Rv2P',
24+
},
25+
{
26+
icon: <FaBook />,
27+
helper: 'Docs; Read the Atomic Data documentation',
28+
href: 'https://docs.atomicdata.dev',
29+
},
30+
];
31+
32+
export function About() {
33+
return (
34+
<>
35+
<SideBarHeader>
36+
<Logo style={{ height: '1.1rem', maxWidth: '100%' }} />
37+
</SideBarHeader>
38+
<AboutWrapper>
39+
{aboutMenuItems.map(p => (
40+
<AboutIcon key={p.helper} {...p} />
41+
))}
42+
</AboutWrapper>
43+
</>
44+
);
45+
}
46+
47+
const AboutWrapper = styled.div`
48+
--inner-padding: 0.5rem;
49+
display: flex;
50+
/* flex-direction: column; */
51+
align-items: center;
52+
gap: 0.5rem;
53+
margin-left: calc(1rem - var(--inner-padding));
54+
`;
55+
56+
interface AboutIconProps {
57+
href?: string;
58+
icon: React.ReactNode;
59+
helper: string;
60+
}
61+
62+
function AboutIcon({ icon, helper, href }: AboutIconProps) {
63+
return (
64+
<StyledAtomicLink href={href} clean title={helper}>
65+
{icon}
66+
</StyledAtomicLink>
67+
);
68+
}
69+
70+
const StyledAtomicLink = styled(AtomicLink)`
71+
padding: 0.5rem;
72+
display: grid;
73+
place-items: center;
74+
aspect-ratio: 1 / 1;
75+
border-radius: ${p => p.theme.radius};
76+
color: ${p => p.theme.colors.textLight};
77+
font-size: 1.6rem;
78+
transition: color 0.1s ease-in-out, background-color 0.1s ease-in-out;
79+
&:hover,
80+
&:focus {
81+
background: ${p => p.theme.colors.bg1};
82+
color: ${p => p.theme.colors.text};
83+
}
84+
`;

data-browser/src/components/SideBar/DriveSwitcher.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { classes, Resource, urls, useResources } from '@tomic/react';
22
import React, { useMemo } from 'react';
33
import {
44
FaCog,
5+
FaHdd,
56
FaPlus,
67
FaRegCheckCircle,
78
FaRegCircle,
8-
FaServer,
99
} from 'react-icons/fa';
1010
import { useNavigate } from 'react-router-dom';
1111
import { useSettings } from '../../helpers/AppSettings';
@@ -19,7 +19,7 @@ import { useDefaultNewInstanceHandler } from '../NewInstanceButton';
1919
import { SideBarButton } from './ResourceSideBar/FloatingActions';
2020

2121
const Trigger = buildDefaultTrigger(
22-
<FaServer />,
22+
<FaHdd />,
2323
SideBarButton,
2424
'Open Drive Settings',
2525
);

0 commit comments

Comments
 (0)