-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
204 additions
and
43 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 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,103 @@ | ||
import * as React from 'react'; | ||
|
||
/* ------------------------------------------------------------------------------------------------- | ||
* Spinner | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
export interface RootProps | ||
extends React.PropsWithoutRef<React.SVGProps<SVGSVGElement>>, | ||
React.RefAttributes<SVGElement | SVGSVGElement> { | ||
/** | ||
* The horizontal (width) and vertical (height) length of the spinner. | ||
*/ | ||
size?: number; | ||
} | ||
|
||
/** | ||
* @docs {@link https://www.vidstack.io/docs/player/components/display/buffering-indicator} | ||
* @example | ||
* ```html | ||
* <Spinner.Root> | ||
* <Spinner.Track /> | ||
* <Spinner.TrackFill /> | ||
* </Spinner> | ||
* ``` | ||
*/ | ||
const Root = React.forwardRef<SVGElement | SVGSVGElement, RootProps>( | ||
({ size, children, ...props }: RootProps, forwardRef) => { | ||
return ( | ||
<svg | ||
width={size} | ||
height={size} | ||
fill="none" | ||
viewBox="0 0 120 120" | ||
aria-hidden="true" | ||
data-part="root" | ||
{...props} | ||
ref={forwardRef as any} | ||
> | ||
{children} | ||
</svg> | ||
); | ||
}, | ||
); | ||
|
||
/* ------------------------------------------------------------------------------------------------- | ||
* Track | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
export interface TrackProps | ||
extends React.PropsWithoutRef<React.SVGProps<SVGCircleElement>>, | ||
React.RefAttributes<SVGCircleElement> {} | ||
|
||
const Track = React.forwardRef<SVGCircleElement, TrackProps>( | ||
({ width, children, ...props }, ref) => ( | ||
<circle | ||
cx="60" | ||
cy="60" | ||
r="54" | ||
stroke="currentColor" | ||
strokeWidth={width} | ||
data-part="track" | ||
{...props} | ||
ref={ref} | ||
> | ||
{children} | ||
</circle> | ||
), | ||
); | ||
|
||
/* ------------------------------------------------------------------------------------------------- | ||
* TrackFill | ||
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
export interface TrackFillProps | ||
extends React.PropsWithoutRef<React.SVGProps<SVGCircleElement>>, | ||
React.RefAttributes<SVGCircleElement> { | ||
/** | ||
* The percentage of the track that should be filled. | ||
*/ | ||
fillPercent?: number; | ||
} | ||
|
||
const TrackFill = React.forwardRef<SVGCircleElement, TrackFillProps>( | ||
({ width, fillPercent = 50, children, ...props }, ref) => ( | ||
<circle | ||
cx="60" | ||
cy="60" | ||
r="54" | ||
stroke="currentColor" | ||
pathLength="100" | ||
strokeWidth={width} | ||
strokeDasharray={100} | ||
strokeDashoffset={100 - fillPercent} | ||
data-part="track-fill" | ||
{...props} | ||
ref={ref} | ||
> | ||
{children} | ||
</circle> | ||
), | ||
); | ||
|
||
export { Root, Track, TrackFill }; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { html } from 'lit-html'; | ||
|
||
import { LitElement } from '../lit/lit-element'; | ||
|
||
/** | ||
* @docs {@link https://www.vidstack.io/docs/wc/player/components/display/buffering-indicator} | ||
* @example | ||
* ```html | ||
* <media-spinner></media-spinner> | ||
* ``` | ||
* @example | ||
* ```css | ||
* media-spinner { | ||
* --size: 84px; | ||
* --track-width: 8px; | ||
* --track-color: rgb(255 255 255 / 0.5); | ||
* --track-fill-color: white; | ||
* --track-fill-percent: 50; | ||
* } | ||
* ``` | ||
*/ | ||
export class MediaSpinnerElement extends LitElement { | ||
static tagName = 'media-spinner'; | ||
|
||
render() { | ||
return html` | ||
<svg | ||
fill="none" | ||
viewBox="0 0 120 120" | ||
aria-hidden="true" | ||
data-part="root" | ||
style="width: var(--size); height: var(--size)" | ||
> | ||
<circle | ||
cx="60" | ||
cy="60" | ||
r="54" | ||
stroke="currentColor" | ||
data-part="track" | ||
style="color: var(--track-color); stroke-width: var(--track-width);" | ||
></circle> | ||
<circle | ||
cx="60" | ||
cy="60" | ||
r="54" | ||
stroke="currentColor" | ||
pathLength="100" | ||
stroke-dasharray="100" | ||
data-part="track-fill" | ||
style="color: var(--track-fill-color); stroke-width: var(--track-width); stroke-dashoffset: calc(100 - var(--track-fill-percent, 50));" | ||
></circle> | ||
</svg> | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'media-spinner': MediaSpinnerElement; | ||
} | ||
} |
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