feat: added rows column props to LayoutSelector (#2945)
This commit is contained in:
parent
ff24b57a4b
commit
fb9744a817
@ -5,7 +5,7 @@ import {
|
|||||||
useViewportGrid,
|
useViewportGrid,
|
||||||
} from '@ohif/ui';
|
} from '@ohif/ui';
|
||||||
|
|
||||||
function LayoutSelector() {
|
function LayoutSelector({rows, columns}) {
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const [viewportGridState, viewportGridService] = useViewportGrid();
|
const [viewportGridState, viewportGridService] = useViewportGrid();
|
||||||
|
|
||||||
@ -41,6 +41,8 @@ function LayoutSelector() {
|
|||||||
dropdownContent={
|
dropdownContent={
|
||||||
DropdownContent !== null && (
|
DropdownContent !== null && (
|
||||||
<DropdownContent
|
<DropdownContent
|
||||||
|
rows={rows}
|
||||||
|
columns={columns}
|
||||||
onSelection={({ numRows, numCols }) => {
|
onSelection={({ numRows, numCols }) => {
|
||||||
viewportGridService.setLayout({ numCols, numRows });
|
viewportGridService.setLayout({ numCols, numRows });
|
||||||
}}
|
}}
|
||||||
|
|||||||
@ -285,6 +285,10 @@ const toolbarButtons = [
|
|||||||
{
|
{
|
||||||
id: 'Layout',
|
id: 'Layout',
|
||||||
type: 'ohif.layoutSelector',
|
type: 'ohif.layoutSelector',
|
||||||
|
props: {
|
||||||
|
rows: 3,
|
||||||
|
columns: 3,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
// More...
|
// More...
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,28 +1,29 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
function LayoutSelector({ onSelection }) {
|
function LayoutSelector({ onSelection, rows, columns}) {
|
||||||
const [hoveredIndex, setHoveredIndex] = useState();
|
const [hoveredIndex, setHoveredIndex] = useState();
|
||||||
const hoverX = hoveredIndex % 3;
|
const hoverX = hoveredIndex % columns;
|
||||||
const hoverY = Math.floor(hoveredIndex / 3);
|
const hoverY = Math.floor(hoveredIndex / columns);
|
||||||
const isHovered = index => {
|
const isHovered = index => {
|
||||||
const x = index % 3;
|
const x = index % columns;
|
||||||
const y = Math.floor(index / 3);
|
const y = Math.floor(index / columns);
|
||||||
|
|
||||||
return x <= hoverX && y <= hoverY;
|
return x <= hoverX && y <= hoverY;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const gridSize = '20px '
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: 'grid',
|
display: 'grid',
|
||||||
gridTemplateColumns: '20px 20px 20px',
|
gridTemplateColumns: gridSize.repeat(columns),
|
||||||
gridTemplateRows: '20px 20px 20px',
|
gridTemplateRows: gridSize.repeat(rows),
|
||||||
backgroundColor: '#090c29', // primary-dark
|
backgroundColor: '#090c29', // primary-dark
|
||||||
}}
|
}}
|
||||||
className="p-2"
|
className="p-2"
|
||||||
>
|
>
|
||||||
{[0, 1, 2, 3, 4, 5, 6, 7, 8].map(index => (
|
{Array.apply(null, Array(rows*columns)).map(function (_, i) {return i;}).map(index => (
|
||||||
<div
|
<div
|
||||||
key={index}
|
key={index}
|
||||||
style={{
|
style={{
|
||||||
@ -31,8 +32,8 @@ function LayoutSelector({ onSelection }) {
|
|||||||
}}
|
}}
|
||||||
className="cursor-pointer"
|
className="cursor-pointer"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const x = index % 3;
|
const x = index % columns;
|
||||||
const y = Math.floor(index / 3);
|
const y = Math.floor(index / columns);
|
||||||
|
|
||||||
onSelection({
|
onSelection({
|
||||||
numRows: y + 1,
|
numRows: y + 1,
|
||||||
@ -49,10 +50,14 @@ function LayoutSelector({ onSelection }) {
|
|||||||
|
|
||||||
LayoutSelector.defaultProps = {
|
LayoutSelector.defaultProps = {
|
||||||
onSelection: () => {},
|
onSelection: () => {},
|
||||||
|
columns: 3,
|
||||||
|
rows: 3
|
||||||
};
|
};
|
||||||
|
|
||||||
LayoutSelector.propTypes = {
|
LayoutSelector.propTypes = {
|
||||||
onSelection: PropTypes.func.isRequired,
|
onSelection: PropTypes.func.isRequired,
|
||||||
|
columns: PropTypes.number.isRequired,
|
||||||
|
rows: PropTypes.number.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default LayoutSelector;
|
export default LayoutSelector;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user