Skip to content

Commit

Permalink
feat: enable to set custom height
Browse files Browse the repository at this point in the history
  • Loading branch information
bigaru committed Oct 17, 2023
1 parent d466f0f commit b463dc1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/blocks/iiifViewer/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
"showInformationPanel": {
"type": "boolean",
"default": true
},
"dynamicHeight": {
"type": "boolean",
"default": true
},
"height": {
"type": "integer",
"default": 200
}
},
"supports": {
Expand Down
31 changes: 30 additions & 1 deletion src/blocks/iiifViewer/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ const urlSchema = {
URL: { type: 'string', format: 'uri', pattern: '^https?://' },
},
}
const MIN_HEIGHT = 200

function EditComponent(props: BlockEditProps<Attributes>) {
const { isSelected } = props

const { inputKey, blockName, isWizardMode, actions, showTitle, showInformationPanel, showBadge } = useGlobalState((state: GlobalState) => state)
const { inputKey, blockName, isWizardMode, actions, showTitle, showInformationPanel, showBadge, dynamicHeight, height } = useGlobalState(
(state: GlobalState) => state
)
const isValueSet = !!inputKey
const { updateState } = actions

Expand Down Expand Up @@ -82,6 +85,32 @@ function EditComponent(props: BlockEditProps<Attributes>) {
onChange={() => updateState({ showBadge: !showBadge })}
/>
</PanelRow>
<PanelRow>
<ToggleControl
label={__('Dynamic Height', 'inseri-core')}
help={dynamicHeight ? __('Height is dynamic.', 'inseri-core') : __('Height is fixed.', 'inseri-core')}
checked={dynamicHeight}
onChange={() => updateState({ dynamicHeight: !dynamicHeight })}
/>
</PanelRow>
{!dynamicHeight && (
<PanelRow>
<div style={{ width: '100%' }}>
<TextControl
label={__('height', 'inseri-core')}
type="number"
min={MIN_HEIGHT}
value={height}
onChange={(value) => {
const newVal = parseInt(value)
if (newVal >= MIN_HEIGHT) {
updateState({ height: newVal })
}
}}
/>
</div>
</PanelRow>
)}
</PanelBody>
</InspectorControls>
{isWizardMode ? (
Expand Down
2 changes: 2 additions & 0 deletions src/blocks/iiifViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface Attributes {
showTitle: boolean
showBadge: boolean
showInformationPanel: boolean
dynamicHeight: boolean
height: number
}

registerBlockType<Attributes>(name, {
Expand Down
4 changes: 3 additions & 1 deletion src/blocks/iiifViewer/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useState } from '@wordpress/element'
import { useAsync } from 'react-use'

export default function View() {
const { inputKey, showTitle, showInformationPanel, showBadge } = useGlobalState((state: GlobalState) => state)
const { inputKey, showTitle, showInformationPanel, showBadge, dynamicHeight, height } = useGlobalState((state: GlobalState) => state)
const { updateState } = useGlobalState((state: GlobalState) => state.actions)
const [loadsManifest, setLoadsManifest] = useState(true)

Expand Down Expand Up @@ -44,6 +44,7 @@ export default function View() {
background: '#F8F9FA',
color: '#868E96',
padding: '8px',
height,
}}
>
<IconCircleOff size={40} />
Expand All @@ -57,6 +58,7 @@ export default function View() {
options={{
showTitle,
showIIIFBadge: showBadge,
canvasHeight: dynamicHeight ? undefined : height,
informationPanel: {
open: false,
renderToggle: showInformationPanel,
Expand Down

0 comments on commit b463dc1

Please sign in to comment.