-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #781 from Stremio/refactor/components
Move components to their own folder
- Loading branch information
Showing
206 changed files
with
310 additions
and
310 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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,71 @@ | ||
// Copyright (C) 2017-2023 Smart code 203358507 | ||
|
||
import { createElement, forwardRef, useCallback } from 'react'; | ||
import classNames from 'classnames'; | ||
import { LongPressEventType, useLongPress } from 'use-long-press'; | ||
import styles from './Button.less'; | ||
|
||
type Props = { | ||
className?: string, | ||
href?: string, | ||
title?: string, | ||
disabled?: boolean, | ||
tabIndex?: number, | ||
children: React.ReactNode, | ||
onKeyDown?: (event: React.KeyboardEvent) => void, | ||
onMouseDown?: (event: React.MouseEvent) => void, | ||
onLongPress?: () => void, | ||
onClick?: (event: React.MouseEvent<HTMLDivElement>) => void, | ||
onDoubleClick?: () => void, | ||
}; | ||
|
||
const Button = forwardRef(({ className, href, disabled, children, onLongPress, onDoubleClick, ...props }: Props, ref) => { | ||
const longPress = useLongPress(onLongPress!, { detect: LongPressEventType.Pointer }); | ||
|
||
const onKeyDown = useCallback((event: React.KeyboardEvent<HTMLDivElement>) => { | ||
if (typeof props.onKeyDown === 'function') { | ||
props.onKeyDown(event); | ||
} | ||
|
||
if (event.key === 'Enter') { | ||
event.preventDefault(); | ||
// @ts-expect-error: Property 'buttonClickPrevented' does not exist on type 'KeyboardEvent'. | ||
if (!event.nativeEvent.buttonClickPrevented) { | ||
event.currentTarget.click(); | ||
} | ||
} | ||
}, [props.onKeyDown]); | ||
|
||
const onMouseDown = useCallback((event: React.MouseEvent<HTMLDivElement>) => { | ||
if (typeof props.onMouseDown === 'function') { | ||
props.onMouseDown(event); | ||
} | ||
|
||
// @ts-expect-error: Property 'buttonBlurPrevented' does not exist on type 'MouseEvent'. | ||
if (!event.nativeEvent.buttonBlurPrevented) { | ||
event.preventDefault(); | ||
if (document.activeElement instanceof HTMLElement) { | ||
document.activeElement.blur(); | ||
} | ||
} | ||
}, [props.onMouseDown]); | ||
|
||
return createElement( | ||
typeof href === 'string' && href.length > 0 ? 'a' : 'div', | ||
{ | ||
tabIndex: 0, | ||
...props, | ||
ref, | ||
className: classNames(className, styles['button-container'], { 'disabled': disabled }), | ||
href, | ||
onKeyDown, | ||
onMouseDown, | ||
onDoubleClick, | ||
...longPress() | ||
}, | ||
children | ||
); | ||
}); | ||
|
||
export default Button; | ||
|
This file contains 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,6 @@ | ||
// Copyright (C) 2017-2023 Smart code 203358507 | ||
|
||
import Button from './Button'; | ||
|
||
export default Button; | ||
|
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.