refactor(packages): dry up core, html, and react UI architecture (#699)

This commit is contained in:
rahim
2026-03-03 23:27:53 -08:00
committed by GitHub
parent 8bdd4ce7fa
commit 1edeadefed
110 changed files with 1349 additions and 1359 deletions
@@ -1,14 +1,10 @@
'use client';
import { SeekButtonCore, SeekButtonDataAttrs } from '@videojs/core';
import { logMissingFeature, selectTime } from '@videojs/core/dom';
import type { ForwardedRef } from 'react';
import { forwardRef, useState } from 'react';
import { selectTime } from '@videojs/core/dom';
import { usePlayer } from '../../player/context';
import type { UIComponentProps } from '../../utils/types';
import { renderElement } from '../../utils/use-render';
import { useButton } from '../hooks/use-button';
import { createMediaButton } from '../create-media-button';
export interface SeekButtonProps extends UIComponentProps<'button', SeekButtonCore.State>, SeekButtonCore.Props {}
@@ -29,40 +25,12 @@ export interface SeekButtonProps extends UIComponentProps<'button', SeekButtonCo
* />
* ```
*/
export const SeekButton = forwardRef(function SeekButton(
componentProps: SeekButtonProps,
forwardedRef: ForwardedRef<HTMLButtonElement>
) {
const { render, className, style, seconds, label, disabled, ...elementProps } = componentProps;
const time = usePlayer(selectTime);
const [core] = useState(() => new SeekButtonCore());
core.setProps({ seconds, label, disabled });
const { getButtonProps, buttonRef } = useButton({
displayName: 'SeekButton',
onActivate: () => core.seek(time!),
isDisabled: () => disabled || !time,
});
if (!time) {
if (__DEV__) logMissingFeature('SeekButton', 'time');
return null;
}
const state = core.getState(time);
return renderElement(
'button',
{ render, className, style },
{
state,
stateAttrMap: SeekButtonDataAttrs,
ref: [forwardedRef, buttonRef],
props: [core.getAttrs(state), elementProps, getButtonProps()],
}
);
export const SeekButton = createMediaButton<SeekButtonCore, SeekButtonProps>({
displayName: 'SeekButton',
core: SeekButtonCore,
stateAttrMap: SeekButtonDataAttrs,
selector: selectTime,
action: (core, state) => core.seek(state),
});
export namespace SeekButton {