-
Notifications
You must be signed in to change notification settings - Fork 41
feat: add many custom components and audio module #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jessebofill
wants to merge
9
commits into
SteamDeckHomebrew:v3
Choose a base branch
from
jessebofill:main
base: v3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
be6a146
feat: add many custom components and audio module
jessebofill 239da8c
fix: fix issue with focus navigation in pretty date picker
jessebofill e0796a9
chore: clear timeouts
jessebofill 3a747cb
chore: change prop name useCustomModal to customModal
jessebofill e36dff8
chore: switch to font awesome icons in custom components
jessebofill 9bc9333
chore: change joinClassNames to accept falsy value args and omit them
jessebofill 3f59858
chore: change sfx in pretty date picker
jessebofill 0c7a7a9
chore: re export all added files
jessebofill ba26755
chore: update CustomButton component
jessebofill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,5 +78,8 @@ | |
| "style": "module", | ||
| "parser": "typescript" | ||
| } | ||
| }, | ||
| "dependencies": { | ||
| "react-icons": "^4.11.0" | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import { ReactNode, FC, useState } from "react"; | ||
| import { FocusableProps, Focusable, DialogButton } from '../deck-components'; | ||
| import { SoundFile, SFXPath, GamepadUIAudio } from '../utils/GamepadUIAudio'; | ||
|
|
||
| export interface CustomButtonProps extends Omit<FocusableProps, 'focusWithinClassName' | 'flow-children' | 'onActivate' | 'onCancel' | 'onClick' | 'children' | 'noFocusRing' | 'onChange'> { | ||
| /** The sound effect to use when clicking @default 'deck_ui_default_activation.wav' */ | ||
| audioSFX?: SoundFile; | ||
|
|
||
| /** Whether or not the button sound effect should be disable @default false */ | ||
| noAudio?: boolean; | ||
|
|
||
| /** Whether or not the button should be transparent @default false */ | ||
| transparent?: boolean; | ||
|
|
||
| /** The type of indicator to use when focused @default highlight */ | ||
| focusMode?: CustomButtonFocusMode; | ||
|
|
||
| /** Callback function to be executed when the button is clicked */ | ||
| onClick?: (e: CustomEvent) => void; | ||
|
|
||
| /** CSS class name for the button's container div */ | ||
| containerClassName?: string; | ||
|
|
||
| /** CSS style for the button's container div */ | ||
| containerStyle?: React.CSSProperties; | ||
|
|
||
| /** Whether or not the button should be diabled @default false */ | ||
| disabled?: boolean; | ||
|
|
||
| /** Whether or not the button should be focusable @default false */ | ||
| focusable?: boolean; | ||
|
|
||
| /** Child elements of the component */ | ||
| children?: ReactNode; | ||
| } | ||
|
|
||
| /** Type of indicator to use when CustomButton is focused*/ | ||
| export enum CustomButtonFocusMode { | ||
| highlight, | ||
| ring | ||
| } | ||
|
|
||
| /** CSS class names for CustomButton component */ | ||
| export enum CustomButtonClasses { | ||
| buttonContainer = 'custom-button-container', | ||
| button = 'custom-button' | ||
| } | ||
|
|
||
| /** A button component with many customizable options */ | ||
| export const CustomButton: FC<CustomButtonProps> = ({ | ||
| audioSFX, | ||
| noAudio, | ||
| disabled, | ||
| focusable, | ||
| transparent, | ||
| focusMode, | ||
| onFocus, | ||
| onBlur, | ||
| onClick, | ||
| style, | ||
| className, | ||
| containerStyle, | ||
| containerClassName, | ||
| focusClassName, | ||
| onOKActionDescription, | ||
| children, | ||
| ...focusableProps | ||
| }) => { | ||
| const [focused, setFocused] = useState(false); | ||
| const focusStyle = focusMode ?? CustomButtonFocusMode.highlight; | ||
|
|
||
| const audioPath: SFXPath = `/sounds/${audioSFX ?? 'deck_ui_default_activation.wav'}`; | ||
|
|
||
| const onClicked = (e: CustomEvent) => { | ||
| if (!disabled) { | ||
| !noAudio && GamepadUIAudio.AudioPlaybackManager.PlayAudioURL(audioPath); | ||
| onClick?.(e); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Focusable | ||
| //@ts-ignore | ||
| onClick={onClicked} | ||
| className={addClasses(CustomButtonClasses.buttonContainer, containerClassName)} | ||
| style={containerStyle} | ||
| onActivate={focusable ?? true ? onClicked : undefined} | ||
| onFocus={(e) => { setFocused(true); onFocus?.(e); }} | ||
| onBlur={(e) => { setFocused(false); onBlur?.(e); }} | ||
| noFocusRing={!(focusMode ?? false)} | ||
| onOKActionDescription={disabled ? '' : onOKActionDescription} | ||
| {...focusableProps} | ||
| > | ||
| <DialogButton | ||
| className={addClasses(CustomButtonClasses.button, className, focusStyle === CustomButtonFocusMode.highlight && focused && 'gpfocus', focused && focusClassName)} | ||
| style={Object.assign(transparent && (focusStyle === CustomButtonFocusMode.ring || !focused) ? { background: 'transparent' } : {}, style ?? {})} | ||
| focusable={false} | ||
| disabled={disabled} | ||
| > | ||
| {children} | ||
| </DialogButton> | ||
| </Focusable> | ||
| ); | ||
| }; | ||
|
|
||
| /** Utility function to join strings for CSS class names omitting invalid values */ | ||
| function addClasses(...strings: any[]) { | ||
jessebofill marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return strings.filter(string => string).join(' '); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| import { SingleDropdownOption, DropdownProps, showContextMenu, Menu, MenuItem, showModal } from '../deck-components'; | ||
| import { ReactElement, VFC, useState, useEffect } from 'react'; | ||
| import { BsThreeDots } from 'react-icons/bs'; | ||
jessebofill marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import { CustomButtonProps, CustomButton } from './CustomButton'; | ||
|
|
||
| export type BaseModalProps = { | ||
| onSelectOption: (option: SingleDropdownOption) => void, | ||
| rgOptions?: SingleDropdownOption[], | ||
| selectedOption?: SingleDropdownOption['data'], | ||
| closeModal?: () => void | ||
| } | ||
|
|
||
| export interface CustomDropdownProps extends Omit<DropdownProps, 'rgOptions' | 'onMenuWillOpen' | 'selectedOption' | 'contextMenuPositionOptions' | 'renderButtonValue'>, Omit<CustomButtonProps, 'audioSFX' | 'noAudio' | 'onClick' | 'children'> { | ||
| /** An array of options to choose from */ | ||
| rgOptions?: SingleDropdownOption[]; | ||
|
|
||
| /** The selected option data */ | ||
| selectedOption?: SingleDropdownOption['data']; | ||
|
|
||
| /** Whether or not the selection label should be centered @default false */ | ||
| labelCenter?: boolean; | ||
|
|
||
| /** A string to always show in place of the selected option's label */ | ||
| labelOverride?: string; | ||
|
|
||
| /** Whether or not the selection dropdown arrow should be removed @default false */ | ||
| noDropdownIcon?: boolean; | ||
|
|
||
| /** An element to use a replacement for the selection dropdown icon */ | ||
| customDropdownIcon?: ReactElement; | ||
|
|
||
| /** A custom modal to use to select options instead of the default context menu */ | ||
| useCustomModal?: VFC<BaseModalProps>; | ||
jessebofill marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** CSS style for the selection label div */ | ||
| labelStyle?: React.CSSProperties; | ||
|
|
||
| /** CSS style for the selection label div when it has changed */ | ||
| labelChangedStyle?: React.CSSProperties; | ||
| } | ||
|
|
||
| /** CSS class names for CustomDropdown component */ | ||
| export enum CustomDropdownClasses { | ||
| topLevel = 'custom-dropdown-container', | ||
| label = 'custom-dropdown-label', | ||
| selectionChanged = 'selection-changed' | ||
| } | ||
|
|
||
| /** A dropdown component with many customizable options */ | ||
| export const CustomDropdown: VFC<CustomDropdownProps> = ({ | ||
| rgOptions, | ||
| selectedOption: selectedOptionData, | ||
| style, | ||
| labelStyle, | ||
| labelChangedStyle, | ||
| containerClassName, | ||
| labelOverride, | ||
| strDefaultLabel, | ||
| labelCenter, | ||
| menuLabel, | ||
| noDropdownIcon, | ||
| customDropdownIcon, | ||
| focusMode, | ||
| transparent, | ||
| onChange, | ||
| useCustomModal: CustomModal, | ||
| onMenuOpened, | ||
| ...buttonProps | ||
| }) => { | ||
| const icon = customDropdownIcon ?? (CustomModal ? <BsThreeDots style={{ margin: 'auto' }} /> : <svg style={{ height: '1em', margin: 'auto' }} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36" fill="none"><path d="M17.98 26.54L3.20996 11.77H32.75L17.98 26.54Z" fill="currentColor"></path></svg>); | ||
TrainDoctor marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const [selected, setSelected] = useState<SingleDropdownOption | undefined>(rgOptions?.find(option => option.data === selectedOptionData)); | ||
| const [changed, setChanged] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| if (changed) { | ||
| setTimeout(() => setChanged(false), 15); | ||
jessebofill marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| }, [changed]); | ||
|
|
||
| useEffect(() => { | ||
| if (selected?.data !== selectedOptionData) { | ||
| setChanged(true); | ||
| setSelected(rgOptions?.find(option => option.data === selectedOptionData)); | ||
| } | ||
| }, [selectedOptionData, rgOptions?.length]); | ||
|
|
||
|
|
||
| const onSelect = (option: SingleDropdownOption) => { | ||
| setChanged(true); | ||
| setSelected(option); | ||
| onChange?.(option); | ||
| }; | ||
|
|
||
| const showDefaultMenu = () => { | ||
| showContextMenu(<Menu label={menuLabel ?? ''} > | ||
| {rgOptions?.map(option => | ||
| <MenuItem selected={option === selected} onClick={() => onSelect(option)}> | ||
| {option.label} | ||
| </MenuItem>)} | ||
| </Menu>); | ||
| onMenuOpened?.(); | ||
| }; | ||
|
|
||
| return ( | ||
| <CustomButton | ||
| containerClassName={addClasses(CustomDropdownClasses.topLevel, containerClassName)} | ||
| style={{ padding: '10px 16px', ...style }} | ||
| noAudio={true} | ||
| focusMode={focusMode} | ||
| transparent={transparent} | ||
| onClick={() => { | ||
| CustomModal ? showModal( | ||
| <CustomModal | ||
| onSelectOption={(option) => onSelect(option)} | ||
| selectedOption={selected?.data} | ||
| rgOptions={rgOptions} | ||
| /> | ||
| ) : rgOptions && showDefaultMenu(); | ||
| }} | ||
| {...buttonProps} | ||
| > | ||
| <div style={{ display: 'flex', overflow: 'hidden' }}> | ||
| <div style={{ overflow: 'hidden', flex: 'auto' }}> | ||
| <div style={Object.assign({ textAlign: labelCenter ? 'center' : 'left', minHeight: '20px' }, changed ? labelChangedStyle : labelStyle)} className={addClasses(CustomDropdownClasses.label, changed && CustomDropdownClasses.selectionChanged)}> | ||
| {labelOverride ?? selected?.label ?? strDefaultLabel} | ||
| </div> | ||
| </div> | ||
| {!noDropdownIcon && ( | ||
| <div style={{ display: 'flex', marginLeft: '1ch', flex: 'none' }}> | ||
| {icon} | ||
| </div> | ||
| )} | ||
| </div> | ||
| </CustomButton> | ||
| ); | ||
| }; | ||
|
|
||
| /** Utility function to join strings for CSS class names omitting invalid values */ | ||
| function addClasses(...strings: any[]) { | ||
jessebofill marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return strings.filter(string => string).join(' '); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.