Skip to content
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

feat: add color property to background prop #54

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/components/Avatar/Avatar.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export interface AvatarProps extends LightingProps, EnvironmentProps, Omit<BaseM
cameraInitialDistance?: number;
/**
* Apply styling to canvas DOM element.
* Note that background property can not be set via style prop, it will always be overridden to `transparent`.
* Instead, use `background` prop for that purpose.
*/
style?: CSSProperties;
/**
Expand All @@ -98,8 +100,10 @@ export interface AvatarProps extends LightingProps, EnvironmentProps, Omit<BaseM
*/
emotion?: Emotion;
/**
* Applies Box background in the scene with a provided image.
* Allows adding a background image and background color to the scene.
* Make sure that image is loadable to prevent bg errors.
* background.src - Accepts URL string.
* background.color - Accepts Hexadeximal, RGB, X11 color name, HSL string, doesn't support CSS gradients.
*/
background?: Background;
/**
Expand Down Expand Up @@ -276,7 +280,7 @@ const Avatar: FC<AvatarProps> = ({
{shadows && <Shadow />}
{background?.src && <Box {...background} />}
{capture && <Capture {...capture} />}
{style?.background && <BackgroundColor color={style.background as string} />}
{background?.color && <BackgroundColor color={background.color} />}
<EffectComposer autoClear={false}>
<Bloom
luminanceThreshold={bloom?.luminanceThreshold}
Expand Down
9 changes: 7 additions & 2 deletions src/components/Avatar/Avatar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ Static.args = {
intensity: 0.1,
materialIntensity: 3.3
},
style: { background: 'rgb(9,20,26)' },
background: {
color: 'rgb(9,20,26)'
},
style: {},
/* eslint-disable no-console */
onLoaded: () => console.info('EVENT: static avatar loaded'),
onLoading: () => console.info('EVENT: loading static avatar')
Expand Down Expand Up @@ -123,7 +126,9 @@ Showcase.args = {
intensity: 1,
materialIntensity: 1
},
style: { background: '#282038' },
background: {
color: '#282038'
},
dpr: 2,
ambientLightColor: '#ffffff',
dirLightColor: '#ffffff',
Expand Down
6 changes: 3 additions & 3 deletions src/components/Avatar/Examples.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const Bloom: StoryFn<BloomConfiguration> = (args: BloomConfiguration | un
dirLightIntensity={2.2}
spotLightIntensity={0.5}
environment="apartment"
style={{
background: 'rgb(9,20,26)'
background={{
color: 'rgb(9,20,26)'
}}
/>
);
Expand Down Expand Up @@ -109,7 +109,7 @@ SpawnEffectAndAnimation.args = {
cameraInitialDistance: CAMERA.CONTROLS.FULL_BODY.MAX_DISTANCE,
modelSrc: getStoryAssetPath('male-emissive.glb'),
animationSrc: getStoryAssetPath('male-idle.glb'),
style: { background: 'rgb(9,20,26)' }
background: { color: 'rgb(9,20,26)' }
};
SpawnEffectAndAnimation.argTypes = {
...ignoreArgTypesOnExamples,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Background/Box/Box.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Mesh, TextureLoader } from 'three';
import { useLoader } from '@react-three/fiber';
import { MeshProps } from '@react-three/fiber/dist/declarations/src/three-types';

export type Background = { src?: string } & MeshProps;
export type Background = { src?: string; color?: string } & MeshProps;

export const Box: FC<Background> = ({ src = '', ...baseProps }) => {
const ref = useRef<Mesh>(null);
Expand Down
2 changes: 1 addition & 1 deletion src/components/BaseCanvas/BaseCanvas.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const BaseCanvas: FC<BaseCanvasProps> = ({
key={fov}
className={`${styles['base-canvas']} ${className ?? ''}`}
shadows="soft"
gl={{ preserveDrawingBuffer: true, toneMappingExposure: 0.5 }}
gl={{ preserveDrawingBuffer: true, toneMappingExposure: 0.5, alpha: true }}
dpr={dpr}
camera={{ fov, position }}
resize={{ scroll: true, debounce: { scroll: 50, resize: 0 } }}
Expand Down