2021-03-03 05:26:47 +00:00
|
|
|
import { updateApplicationLayout } from "actions/applicationActions";
|
|
|
|
|
import Dropdown from "components/ads/Dropdown";
|
|
|
|
|
import Icon, { IconName, IconSize } from "components/ads/Icon";
|
|
|
|
|
import { Colors } from "constants/Colors";
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { useDispatch } from "react-redux";
|
|
|
|
|
import {
|
|
|
|
|
AppLayoutConfig,
|
2021-03-11 02:21:48 +00:00
|
|
|
SupportedLayouts,
|
2021-03-03 05:26:47 +00:00
|
|
|
} from "reducers/entityReducers/pageListReducer";
|
|
|
|
|
import {
|
|
|
|
|
getCurrentApplicationId,
|
|
|
|
|
getCurrentApplicationLayout,
|
|
|
|
|
} from "selectors/editorSelectors";
|
|
|
|
|
import { useSelector } from "store";
|
2021-03-15 12:17:56 +00:00
|
|
|
import styled from "styled-components";
|
2021-03-03 05:26:47 +00:00
|
|
|
import { noop } from "utils/AppsmithUtils";
|
|
|
|
|
|
|
|
|
|
interface AppsmithLayoutConfigOption {
|
2021-03-11 02:21:48 +00:00
|
|
|
name: string;
|
|
|
|
|
type: SupportedLayouts;
|
2021-03-03 05:26:47 +00:00
|
|
|
icon?: IconName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const AppsmithDefaultLayout: AppLayoutConfig = {
|
2021-03-11 02:21:48 +00:00
|
|
|
type: "DESKTOP",
|
2021-03-03 05:26:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const AppsmithLayouts: AppsmithLayoutConfigOption[] = [
|
|
|
|
|
{
|
|
|
|
|
name: "Desktop",
|
|
|
|
|
...AppsmithDefaultLayout,
|
|
|
|
|
icon: "desktop",
|
|
|
|
|
},
|
2021-03-11 02:21:48 +00:00
|
|
|
{
|
|
|
|
|
name: "Tablet(Large)",
|
|
|
|
|
type: "TABLET_LARGE",
|
|
|
|
|
icon: "tablet",
|
|
|
|
|
},
|
2021-03-03 05:26:47 +00:00
|
|
|
{
|
|
|
|
|
name: "Tablet",
|
2021-03-11 02:21:48 +00:00
|
|
|
type: "TABLET",
|
2021-03-03 05:26:47 +00:00
|
|
|
icon: "tablet",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Mobile Device",
|
2021-03-11 02:21:48 +00:00
|
|
|
type: "MOBILE",
|
2021-03-03 05:26:47 +00:00
|
|
|
icon: "mobile",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Fluid Width",
|
|
|
|
|
type: "FLUID",
|
|
|
|
|
icon: "fluid",
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const LayoutControlWrapper = styled.div`
|
2021-09-06 08:57:47 +00:00
|
|
|
position: absolute;
|
|
|
|
|
height: ${(props) => props.theme.spaces[15]}px;
|
|
|
|
|
width: 100%;
|
2021-03-03 05:26:47 +00:00
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
.bp3-popover-target {
|
|
|
|
|
pointer-events: none;
|
|
|
|
|
}
|
|
|
|
|
.layout-control {
|
|
|
|
|
pointer-events: all;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
border: none;
|
|
|
|
|
box-shadow: none;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
export function MainContainerLayoutControl() {
|
2021-03-03 05:26:47 +00:00
|
|
|
const appId = useSelector(getCurrentApplicationId);
|
|
|
|
|
const appLayout = useSelector(getCurrentApplicationLayout);
|
|
|
|
|
const layoutOptions = AppsmithLayouts.map((each) => {
|
|
|
|
|
return {
|
|
|
|
|
...each,
|
2021-03-29 15:47:22 +00:00
|
|
|
iconSize: IconSize.SMALL,
|
|
|
|
|
iconColor: Colors.BLACK,
|
2021-03-03 05:26:47 +00:00
|
|
|
value: each.name,
|
|
|
|
|
onSelect: () =>
|
|
|
|
|
updateAppLayout({
|
|
|
|
|
type: each.type,
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
const selectedLayout = appLayout
|
2021-03-11 02:21:48 +00:00
|
|
|
? layoutOptions.find((each) => each.type === appLayout.type)
|
2021-03-03 05:26:47 +00:00
|
|
|
: layoutOptions[0];
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
|
|
const updateAppLayout = (layoutConfig: AppLayoutConfig) => {
|
2021-03-11 02:21:48 +00:00
|
|
|
const { type } = layoutConfig;
|
2021-03-03 05:26:47 +00:00
|
|
|
dispatch(
|
|
|
|
|
updateApplicationLayout(appId || "", {
|
|
|
|
|
appLayout: {
|
|
|
|
|
type,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
return (
|
|
|
|
|
<LayoutControlWrapper>
|
|
|
|
|
<div className="layout-control t--layout-control-wrapper">
|
2021-03-15 12:17:56 +00:00
|
|
|
<Dropdown
|
|
|
|
|
SelectedValueNode={({ selected }) => {
|
|
|
|
|
return (
|
|
|
|
|
<Icon
|
|
|
|
|
fillColor={Colors.BLACK}
|
|
|
|
|
name={selected.icon}
|
2021-07-07 09:30:06 +00:00
|
|
|
size={selected.iconSize || IconSize.SMALL}
|
2021-03-15 12:17:56 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
className="layout-control"
|
2021-04-28 10:28:39 +00:00
|
|
|
onSelect={noop}
|
2021-03-15 12:17:56 +00:00
|
|
|
options={layoutOptions}
|
|
|
|
|
selected={selectedLayout || layoutOptions[0]}
|
2021-04-28 10:28:39 +00:00
|
|
|
showDropIcon={false}
|
|
|
|
|
width={"30px"}
|
2021-03-15 12:17:56 +00:00
|
|
|
/>
|
2021-03-03 05:26:47 +00:00
|
|
|
</div>
|
|
|
|
|
</LayoutControlWrapper>
|
|
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|