-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add toggle to fit raw image (on by default)
- Loading branch information
Showing
11 changed files
with
153 additions
and
52 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
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,42 @@ | ||
import { createContext, useContext, useState } from 'react'; | ||
import type { StoreApi } from 'zustand'; | ||
import { createStore, useStore } from 'zustand'; | ||
import { persist } from 'zustand/middleware'; | ||
|
||
import type { ConfigProviderProps } from '../../models'; | ||
|
||
export interface RawConfig { | ||
fitImage: boolean; | ||
toggleFitImage: () => void; | ||
} | ||
|
||
function createRawConfigStore() { | ||
return createStore<RawConfig>()( | ||
persist( | ||
(set): RawConfig => ({ | ||
fitImage: true, | ||
toggleFitImage: () => set((state) => ({ fitImage: !state.fitImage })), | ||
}), | ||
{ | ||
name: 'h5web:raw', | ||
version: 1, | ||
}, | ||
), | ||
); | ||
} | ||
|
||
const StoreContext = createContext({} as StoreApi<RawConfig>); | ||
|
||
export function RawConfigProvider(props: ConfigProviderProps) { | ||
const { children } = props; | ||
|
||
const [store] = useState(createRawConfigStore); | ||
|
||
return ( | ||
<StoreContext.Provider value={store}>{children}</StoreContext.Provider> | ||
); | ||
} | ||
|
||
export function useRawConfig(): RawConfig { | ||
return useStore(useContext(StoreContext)); | ||
} |
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,21 @@ | ||
.root { | ||
flex: 1; /* fill height if inside flex container in consumer app */ | ||
overflow: auto; | ||
scrollbar-width: thin; | ||
} | ||
|
||
.img { | ||
display: block; | ||
} | ||
|
||
.img[data-fit] { | ||
max-width: 100%; | ||
max-height: 100%; | ||
} | ||
|
||
.img:not([data-fit]) { | ||
/* Remove size restriction explicitly in case consumer app applies | ||
* its own "responsive image" styles (like VS Code). */ | ||
max-width: none; | ||
max-height: none; | ||
} |
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,26 @@ | ||
import type { ClassStyleAttrs } from '../models'; | ||
import styles from './RawImageVis.module.css'; | ||
|
||
interface Props extends ClassStyleAttrs { | ||
value: Uint8Array; | ||
title?: string; | ||
fit?: boolean; | ||
} | ||
|
||
function RawImageVis(props: Props) { | ||
const { value, title, fit, className = '', style } = props; | ||
|
||
return ( | ||
<div className={`${styles.root} ${className}`} style={style}> | ||
<img | ||
className={styles.img} | ||
src={URL.createObjectURL(new Blob([value]))} | ||
alt={title} | ||
data-keep-colors | ||
data-fit={fit || undefined} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default RawImageVis; |
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