improve buttons

This commit is contained in:
Uriel committed 2024-11-21 20:20:43 +01:00
1 parent 6a8786b241
commit 96fa13aea9
7 files changed
+176 -19

No files matched your search

+1
View File
@@ -77,6 +77,7 @@
"spdx-satisfies": "^5.0.1",
"tailwind-gradient-mask-image": "^1.2.0",
"tailwindcss": "^3.4.13",
"ts-xor": "^1.3.0",
"vite": "^5.4.8"
}
}
+5
View File
@@ -60,6 +60,7 @@ import { UsageChoose } from './components/onboarding/pages/usage-reason/UsageCho
import { VRUsageChoose } from './components/onboarding/pages/usage-reason/VRUsageChoose';
import { StandaloneUsageSetup } from './components/onboarding/pages/usage-reason/StandaloneUsageSetup';
import { HeadTrackingChoose } from './components/onboarding/pages/usage-reason/HeadTrackingChoose';
import { MocapDataChoose } from './components/onboarding/pages/usage-reason/MocapDataChoose';
export const GH_REPO = 'SlimeVR/SlimeVR-Server';
export const VersionContext = createContext('');
@@ -146,6 +147,10 @@ function Layout() {
path="usage/mocap/head-choose"
element={<HeadTrackingChoose />}
/>
<Route
path="usage/mocap/data-choose"
element={<MocapDataChoose />}
/>
<Route path="trackers-assign" element={<TrackersAssignPage />} />
<Route path="enter-vr" element={<EnterVRPage />} />
<Route path="mounting/choose" element={<MountingChoose />}></Route>
+21 -9
View File
@@ -2,6 +2,7 @@ import classNames from 'classnames';
import React, { ReactNode, useMemo } from 'react';
import { NavLink } from 'react-router-dom';
import { LoaderIcon, SlimeState } from './icon/LoaderIcon';
import { XOR } from 'ts-xor';
function ButtonContent({
loading,
@@ -36,6 +37,25 @@ function ButtonContent({
);
}
type ButtonBaseParams = {
children?: ReactNode;
icon?: ReactNode;
variant: 'primary' | 'secondary' | 'tertiary' | 'quaternary';
loading?: boolean;
rounded?: boolean;
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'>;
type ButtonNavigateParams = { to: string; state?: any } & ButtonBaseParams;
type ButtonScriptParams = {
onClick?: React.MouseEventHandler<HTMLButtonElement>;
} & ButtonBaseParams;
type ButtonSubmitParams = { type: 'submit' } & ButtonBaseParams;
type ButtonParams = XOR<
ButtonNavigateParams,
ButtonScriptParams,
ButtonSubmitParams
>;
export function Button({
children,
variant,
@@ -46,15 +66,7 @@ export function Button({
icon,
rounded = false,
...props
}: {
children?: ReactNode;
icon?: ReactNode;
variant: 'primary' | 'secondary' | 'tertiary' | 'quaternary';
to?: string;
loading?: boolean;
rounded?: boolean;
state?: any;
} & React.ButtonHTMLAttributes<HTMLButtonElement>) {
}: ButtonParams) {
const classes = useMemo(() => {
const variantsMap = {
primary: classNames({
@@ -33,7 +33,7 @@ export function EnterVRPage() {
</div>
<div className="w-full py-4 flex flex-row">
<div className="flex flex-grow">
<Button variant="secondary" to="/" onClick={skipSetup}>
<Button variant="secondary" onClick={skipSetup}>
{l10n.getString('onboarding-skip')}
</Button>
</div>
@@ -8,6 +8,7 @@ import { useStatusContext } from '@/hooks/status-system';
import { Localized, useLocalization } from '@fluent/react';
import classNames from 'classnames';
import { useMemo, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { StatusData, StatusSteamVRDisconnectedT } from 'solarxr-protocol';
export function HeadTrackingChoose() {
@@ -15,6 +16,7 @@ export function HeadTrackingChoose() {
const { applyProgress, state } = useOnboarding();
const { statuses } = useStatusContext();
const [animated, setAnimated] = useState(false);
const navigate = useNavigate();
const missingSteamVr = useMemo(
() =>
@@ -80,9 +82,13 @@ export function HeadTrackingChoose() {
</div>
<Button
variant={!state.alonePage ? 'secondary' : 'tertiary'}
to={'/onboarding/usage/vr/standalone'}
className="self-start mt-auto"
state={{ alonePage: state.alonePage }}
onClick={() => {
// TODO: enable mocap
navigate('/onboarding/usage/mocap/data-choose', {
state: { alonePage: state.alonePage },
});
}}
>
{l10n.getString(
'onboarding-usage-mocap-head_choose-standalone-button'
@@ -0,0 +1,125 @@
import { useOnboarding } from '@/hooks/onboarding';
import { useLocalization } from '@fluent/react';
import { Typography } from '@/components/commons/Typography';
import { useForm } from 'react-hook-form';
import { Radio } from '@/components/commons/Radio';
import { Button } from '@/components/commons/Button';
enum UsageReason {
VR,
VTUBING,
MOCAP,
}
interface UsageInfo {
path: string;
image: string;
}
const REASON_TO_PATH: Record<UsageReason, UsageInfo> = {
[UsageReason.MOCAP]: {
path: '/onboarding/usage/mocap/head-choose',
image: '/images/usage-mocap.webp',
},
[UsageReason.VR]: {
path: '/onboarding/usage/vr/choose',
image: '/images/usage-vr.webp',
},
[UsageReason.VTUBING]: {
path: '/onboarding/usage/vtubing/choose',
image: '/images/usage-vtuber.webp',
},
};
export function MocapDataChoose() {
const { l10n } = useLocalization();
const { applyProgress } = useOnboarding();
const { control, watch } = useForm<{
usageReason: UsageReason;
}>({
defaultValues: {
usageReason: UsageReason.VR,
},
});
const usageReason = watch('usageReason');
const ItemContent = ({ mode }: { mode: UsageReason }) => (
<>
<Typography variant="main-title" textAlign="text-right">
{l10n.getString('onboarding-usage-choose-option-title', {
mode,
})}
</Typography>
<div className="flex flex-col">
<Typography>
{l10n.getString('onboarding-usage-choose-option-label', {
mode,
})}
</Typography>
<Typography variant="standard" color="secondary">
{l10n.getString('onboarding-usage-choose-option-description', {
mode,
})}
</Typography>
</div>
</>
);
applyProgress(0.6);
return (
<div className="flex flex-col gap-5 h-full items-center w-full justify-center">
<div className="flex flex-col w-full overflow-y-auto px-4 xs:items-center">
<div className="flex mobile:flex-col xs:gap-8 mobile:gap-4 mobile:pb-4 w-full justify-center">
<div className="flex flex-col xs:max-w-sm gap-3 justify-center">
<Typography variant="main-title">
{l10n.getString('onboarding-usage-choose')}
</Typography>
<Typography color="secondary">
{l10n.getString('onboarding-usage-choose-description')}
</Typography>
{Object.values(UsageReason)
.filter(checkIfUsageReason)
.map((mode) => (
<Radio
key={mode}
name="usageReason"
control={control}
value={mode.toString()}
className="hidden"
>
<div className="flex flex-row md:gap-4 gap-2">
<ItemContent mode={mode}></ItemContent>
</div>
</Radio>
))}
<div className="flex flex-row">
<Button variant="secondary" to="/onboarding/assign-tutorial">
{l10n.getString('onboarding-previous_step')}
</Button>
<Button
variant="primary"
to={REASON_TO_PATH[usageReason].path}
className="ml-auto"
>
{l10n.getString('onboarding-enter_vr-ready')}
</Button>
</div>
</div>
<div className="flex flex-col justify-center">
<img
className="mobile:hidden rounded-3xl"
src={REASON_TO_PATH[usageReason].image}
width="496"
></img>
</div>
</div>
</div>
</div>
);
}
function checkIfUsageReason(val: any): val is UsageReason {
return typeof val === 'number';
}
+15 -7
View File
@@ -164,7 +164,7 @@ importers:
version: 8.57.1
eslint-config-airbnb:
specifier: ^19.0.4
version: 19.0.4([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]))([email protected]([email protected]))([email protected]([email protected]))([email protected]([email protected]))([email protected])
version: 19.0.4([email protected])([email protected]([email protected]))([email protected]([email protected]))([email protected]([email protected]))([email protected])
eslint-import-resolver-typescript:
specifier: ^3.6.3
version: 3.6.3(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])
@@ -198,6 +198,9 @@ importers:
tailwindcss:
specifier: ^3.4.13
version: 3.4.13([email protected]([email protected]))
ts-xor:
specifier: ^1.3.0
version: 1.3.0
vite:
specifier: ^5.4.8
version: 5.4.8(@types/[email protected])([email protected])([email protected])
@@ -2922,6 +2925,9 @@ packages:
[email protected]:
resolution: {integrity: sha512-hgfOMfjlrARCnYtGD/xEAkFHDXuSyuqjzFSltyQCbN689uNvoQL20TVN2XFcLMjfNuwSsQGU+xtH6MrjIwhwUg==}
[email protected]:
resolution: {integrity: sha512-RLXVjliCzc1gfKQFLRpfeD0rrWmjnSTgj7+RFhoq3KRkUYa8LE/TIidYOzM5h+IdFBDSjjSgk9Lto9sdMfDFEA==}
[email protected]:
resolution: {integrity: sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg==}
@@ -4488,7 +4494,7 @@ snapshots:
[email protected]: {}
[email protected]([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]))([email protected]):
[email protected]([email protected])([email protected]):
dependencies:
confusing-browser-globals: 1.0.11
eslint: 8.57.1
@@ -4497,10 +4503,10 @@ snapshots:
object.entries: 1.1.8
semver: 6.3.1
[email protected]([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]))([email protected]([email protected]))([email protected]([email protected]))([email protected]([email protected]))([email protected]):
[email protected]([email protected])([email protected]([email protected]))([email protected]([email protected]))([email protected]([email protected]))([email protected]):
dependencies:
eslint: 8.57.1
eslint-config-airbnb-base: 15.0.0([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]))([email protected])
eslint-config-airbnb-base: 15.0.0([email protected])([email protected])
eslint-plugin-import: 2.31.0(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])
eslint-plugin-jsx-a11y: 6.10.0([email protected])
eslint-plugin-react: 7.37.1([email protected])
@@ -4522,7 +4528,7 @@ snapshots:
debug: 4.3.7
enhanced-resolve: 5.17.1
eslint: 8.57.1
eslint-module-utils: 2.12.0(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]))([email protected])
eslint-module-utils: 2.12.0(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])([email protected])
fast-glob: 3.3.2
get-tsconfig: 4.8.1
is-bun-module: 1.2.1
@@ -4535,7 +4541,7 @@ snapshots:
- eslint-import-resolver-webpack
- supports-color
[email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]))([email protected]):
[email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])([email protected]):
dependencies:
debug: 3.2.7
optionalDependencies:
@@ -4557,7 +4563,7 @@ snapshots:
doctrine: 2.1.0
eslint: 8.57.1
eslint-import-resolver-node: 0.3.9
eslint-module-utils: 2.12.0(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected](@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected]))([email protected])
eslint-module-utils: 2.12.0(@typescript-eslint/[email protected]([email protected])([email protected]))([email protected])([email protected])([email protected])
hasown: 2.0.2
is-core-module: 2.15.1
is-glob: 4.0.3
@@ -6099,6 +6105,8 @@ snapshots:
[email protected]: {}
[email protected]: {}
[email protected]:
dependencies:
'@types/json5': 0.0.29