Skip to content

Commit

Permalink
feat: default copy component (#220)
Browse files Browse the repository at this point in the history
* feat: default copy component

* refactor: ref imports
  • Loading branch information
thenick775 authored Nov 30, 2024
1 parent 2bbe321 commit 8ce3f70
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 39 deletions.
4 changes: 2 additions & 2 deletions gbajs3/src/components/controls/virtual-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import {
import { useAddCallbacks } from '../../hooks/emulator/use-add-callbacks.tsx';
import { useQuickReload } from '../../hooks/emulator/use-quick-reload.tsx';
import { UploadSaveToServerModal } from '../modals/upload-save-to-server.tsx';
import { Copy } from '../shared/styled.tsx';

import type { AreVirtualControlsEnabledProps } from '../modals/controls/virtual-controls-form.tsx';

const VirtualButtonTextLarge = styled.p`
const VirtualButtonTextLarge = styled(Copy)`
text-align: center;
vertical-align: middle;
line-height: 54px;
color: ${({ theme }) => theme.pureWhite};
margin: 0;
font-size: 1.5em;
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { MinusSquare, PlusSquare } from '../../shared/action-box-icons.tsx';
import { ButtonBase } from '../../shared/custom-button-base.tsx';
import { ManagedCheckbox } from '../../shared/managed-checkbox.tsx';
import { ManagedSwitch } from '../../shared/managed-switch.tsx';
import { Copy } from '../../shared/styled.tsx';

import type { CoreCallbackOptions } from '../../../hooks/emulator/use-add-callbacks.tsx';

Expand All @@ -36,8 +37,7 @@ const StyledForm = styled.form`
}
`;

const OptionsFormTitle = styled.p`
margin: 0;
const OptionsFormTitle = styled(Copy)`
${fileSystemFontStyle}
`;

Expand Down
5 changes: 1 addition & 4 deletions gbajs3/src/components/modals/upload-public-external-roms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
LoadingIndicator,
PacmanIndicator
} from '../shared/loading-indicator.tsx';
import { Copy } from '../shared/styled.tsx';

import type { PublicRomUploadStatus } from '../../hooks/use-show-load-public-roms.tsx';

Expand All @@ -33,10 +34,6 @@ const LinkBreakWord = styled.a`
word-break: break-all;
`;

const Copy = styled.p`
margin: 0;
`;

const URLDisplay = ({ url }: { url: URL }) => {
return (
<Accordion>
Expand Down
16 changes: 7 additions & 9 deletions gbajs3/src/components/shared/custom-button-base.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { type ReactNode } from 'react';
import { forwardRef, type ReactNode } from 'react';
import { styled } from 'styled-components';

type ButtonBaseProps = {
Expand All @@ -16,12 +16,10 @@ const StyledButton = styled.button`
padding: inherit;
`;

export const ButtonBase = React.forwardRef<HTMLButtonElement, ButtonBaseProps>(
({ children, ...rest }, ref) => {
return (
<StyledButton ref={ref} {...rest}>
{children}
</StyledButton>
);
}
export const ButtonBase = forwardRef<HTMLButtonElement, ButtonBaseProps>(
({ children, ...rest }, ref) => (
<StyledButton ref={ref} {...rest}>
{children}
</StyledButton>
)
);
5 changes: 3 additions & 2 deletions gbajs3/src/components/shared/error-with-icon.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { styled } from 'styled-components';

import { Copy } from './styled.tsx';

type ErrorWithIconProps = {
text: string;
icon: JSX.Element;
Expand All @@ -12,8 +14,7 @@ const ErrorWrapper = styled.div`
gap: 5px;
`;

const ErrorText = styled.p`
margin: 0;
const ErrorText = styled(Copy)`
color: ${({ theme }) => theme.errorRed};
`;

Expand Down
6 changes: 3 additions & 3 deletions gbajs3/src/components/shared/loading-indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const LoadingContainer = styled.div`
margin-bottom: 15px;
`;

const Copy = styled.p`
const BreakWord = styled.p`
word-wrap: break-word;
max-width: 100%;
`;
Expand All @@ -47,11 +47,11 @@ export const LoadingIndicator = ({
}: LoadingIndicatorProps) => {
return isLoading ? (
<LoadingContainer>
<Copy>
<BreakWord>
{loadingCopy}
<br />
{currentName}
</Copy>
</BreakWord>
{indicator}
</LoadingContainer>
) : (
Expand Down
4 changes: 2 additions & 2 deletions gbajs3/src/components/shared/managed-checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Checkbox, FormControlLabel, type CheckboxProps } from '@mui/material';
import React from 'react';
import { forwardRef } from 'react';

type ManagedCheckBoxProps = {
label: string;
Expand All @@ -9,7 +9,7 @@ type ManagedCheckBoxProps = {
// Shared managed checkbox component with label
// Params: takes in label, button props,
// and a watcher indicating the current value
export const ManagedCheckbox = React.forwardRef<
export const ManagedCheckbox = forwardRef<
HTMLButtonElement,
ManagedCheckBoxProps
>(({ id, label, watcher, ...rest }, ref) => (
Expand Down
25 changes: 12 additions & 13 deletions gbajs3/src/components/shared/managed-switch.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Switch, FormControlLabel, type SwitchProps } from '@mui/material';
import React from 'react';
import { forwardRef } from 'react';

type ManagedSwitchProps = {
label: string;
Expand All @@ -9,15 +9,14 @@ type ManagedSwitchProps = {
// Shared managed switch component with label
// Params: takes in label, switch props,
// and a watcher indicating the current value
export const ManagedSwitch = React.forwardRef<
HTMLButtonElement,
ManagedSwitchProps
>(({ id, label, watcher, ...rest }, ref) => (
<FormControlLabel
data-testid="managed-switch:label"
id={id}
control={<Switch ref={ref} checked={!!watcher} {...rest} />}
label={label}
style={{ margin: 0 }}
/>
));
export const ManagedSwitch = forwardRef<HTMLButtonElement, ManagedSwitchProps>(
({ id, label, watcher, ...rest }, ref) => (
<FormControlLabel
data-testid="managed-switch:label"
id={id}
control={<Switch ref={ref} checked={!!watcher} {...rest} />}
label={label}
style={{ margin: 0 }}
/>
)
);
7 changes: 5 additions & 2 deletions gbajs3/src/components/shared/styled.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { BiPlus } from 'react-icons/bi';
import { styled } from 'styled-components';

export const CenteredText = styled.p`
text-align: center;
export const Copy = styled.p`
margin: 0;
`;

export const CenteredText = styled(Copy)`
text-align: center;
`;

export const Header = styled.h3`
margin: 0;
`;
Expand Down

0 comments on commit 8ce3f70

Please sign in to comment.