Skip to content

Commit

Permalink
Merge pull request #20 from trilogy-group/feature/param-dropdown
Browse files Browse the repository at this point in the history
Feature/param dropdown
  • Loading branch information
rishabh-ti authored Oct 18, 2022
2 parents fb20416 + 7fb0f38 commit 365d58e
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/components/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const Editor: React.FC = () => {
selectedComponent,
)
let panelCode = await generatePanel(components, fileName)
const response = await API.post('/save-file', {
await API.post('/save-file', {
codeBody: code,
ocTsxBody: ocTsxCode,
jsonBody: components,
Expand Down
3 changes: 3 additions & 0 deletions src/components/inspector/controls/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Grid,
Box,
} from '@chakra-ui/react'
import ParamSelector from '~custom-components/paramSelector'

type FormControlPropType = {
label: ReactNode
Expand Down Expand Up @@ -37,6 +38,8 @@ const FormControl: React.FC<FormControlPropType> = ({
>
{label}
</FormLabel>
<ParamSelector prop={htmlFor} />

<Box
display="flex"
alignItems="center"
Expand Down
2 changes: 2 additions & 0 deletions src/components/inspector/controls/HuesPickerControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Box,
Slider,
} from '@chakra-ui/react'
import ParamSelector from '~custom-components/paramSelector'

type HuesPickerPropType = {
name: string
Expand All @@ -23,6 +24,7 @@ const HuesPickerControl = (props: HuesPickerPropType) => {

return (
<>
<ParamSelector prop={props.name} />
<Grid mb={2} templateColumns="repeat(5, 1fr)" gap={0}>
{Object.keys(props.themeColors).map(colorName =>
props.gradient ? (
Expand Down
2 changes: 0 additions & 2 deletions src/components/inspector/controls/TextControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ const TextControl: React.FC<TextControlPropsType> = ({
}) => {
const { setValueFromEvent } = useForm()
const value = usePropsSelector(name)

return (
<FormControl hasColumn={hasColumn} htmlFor={name} label={label}>
<Input
borderRadius="md"
autoComplete="off"
id={name}
name={name}
Expand Down
52 changes: 39 additions & 13 deletions src/components/inspector/panels/CustomPropsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ import {
Input,
ButtonGroup,
Button,
Menu,
MenuButton,
MenuList,
MenuItem,
InputRightAddon,
Portal,
} from '@chakra-ui/react'
import { EditIcon, SmallCloseIcon } from '@chakra-ui/icons'
import { ChevronDownIcon, EditIcon, SmallCloseIcon } from '@chakra-ui/icons'
import useDispatch from '~hooks/useDispatch'
import { useForm } from '~hooks/useForm'

Expand Down Expand Up @@ -72,33 +78,53 @@ const CustomPropsPanel = () => {
}
}}
>
<InputGroup size="sm">
<Input
ref={inputRef}
isInvalid={hasError}
value={quickProps.name}
placeholder={`prop`}
onChange={(event: ChangeEvent<HTMLInputElement>) =>
setQuickProps({ ...quickProps, name: event.target.value })
}
/>
<Input
size="sm"
ref={inputRef}
isInvalid={hasError}
value={quickProps.name}
placeholder={`prop`}
onChange={(event: ChangeEvent<HTMLInputElement>) =>
setQuickProps({ ...quickProps, name: event.target.value })
}
/>
<InputGroup size="sm" my={1}>
<Input
isInvalid={hasError}
value={quickProps.value}
placeholder={`value`}
onChange={(event: ChangeEvent<HTMLInputElement>) =>
setQuickProps({ ...quickProps, value: event.target.value })
}
ml={1}
/>
<InputRightAddon>
<Menu>
<MenuButton type="button">
<ChevronDownIcon />
</MenuButton>
<Portal>
<MenuList>
{params?.map((param: string) => (
<MenuItem
key={param}
onClick={() =>
setQuickProps({ ...quickProps, value: param })
}
>
{param}
</MenuItem>
))}
</MenuList>
</Portal>
</Menu>
</InputRightAddon>
</InputGroup>
<Flex>
<Button
mr={0}
type="submit"
size="xs"
variant="outline"
mt={0.5}
width="100%"
bgColor="lightblue"
>
Expand Down
65 changes: 23 additions & 42 deletions src/components/inspector/panels/ParametersPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
MenuItem,
Tooltip,
InputRightAddon,
Portal,
} from '@chakra-ui/react'
import {
ChevronDownIcon,
Expand All @@ -30,6 +31,8 @@ import useDispatch from '~hooks/useDispatch'
import { useParamsForm } from '~hooks/useParamsForm'
import { getSelectedCustomComponentId } from '~core/selectors/customComponents'

const paramTypes = ['string', 'number', 'boolean', 'Function', 'any']

const ParametersPanel = () => {
const dispatch = useDispatch()
const inputRef = useRef<HTMLInputElement>(null)
Expand Down Expand Up @@ -89,7 +92,6 @@ const ParametersPanel = () => {
<Flex direction="column">
<InputGroup size="sm">
<Input
mb={1}
isInvalid={hasError}
value={quickParams.type}
placeholder={`type`}
Expand All @@ -103,43 +105,26 @@ const ParametersPanel = () => {
<MenuButton type="button">
<ChevronDownIcon />
</MenuButton>
<MenuList>
<MenuItem
onClick={() =>
setQuickParams({ ...quickParams, type: 'string' })
}
>
string
</MenuItem>
<MenuItem
onClick={() =>
setQuickParams({ ...quickParams, type: 'number' })
}
>
number
</MenuItem>
<MenuItem
onClick={() =>
setQuickParams({ ...quickParams, type: 'boolean' })
}
>
boolean
</MenuItem>
<MenuItem
onClick={() =>
setQuickParams({ ...quickParams, type: 'any' })
}
>
any
</MenuItem>
</MenuList>
<Portal>
<MenuList>
{paramTypes.map((type: string) => (
<MenuItem
key={type}
onClick={() =>
setQuickParams({ ...quickParams, type: type })
}
>
{type}
</MenuItem>
))}
</MenuList>
</Portal>
</Menu>
</InputRightAddon>
</InputGroup>
<Flex direction="row">
<Flex direction="row" mt={1}>
<Input
ref={inputRef}
mr={0.5}
size="sm"
isInvalid={hasError}
value={quickParams.name}
Expand All @@ -149,7 +134,7 @@ const ParametersPanel = () => {
}
/>
<Input
ml={0.5}
ml={1}
size="sm"
isInvalid={hasError}
value={quickParams.value}
Expand Down Expand Up @@ -182,19 +167,13 @@ const ParametersPanel = () => {
</Checkbox>
<Spacer />
</Flex>
<Button
type="submit"
size="xs"
variant="outline"
my={0.5}
bgColor="lightblue"
>
<Button type="submit" size="xs" variant="outline" bgColor="lightblue">
Save
</Button>
</Flex>
</form>

{customParams && (
{customParams?.length ? (
<SimpleGrid width="100%" columns={4} spacing={1} bgColor="yellow.100">
<Box fontSize="sm" fontWeight="bold" pl={1}>
Name
Expand All @@ -204,6 +183,8 @@ const ParametersPanel = () => {
</Box>
<Box fontSize="sm">Value</Box>
</SimpleGrid>
) : (
<></>
)}
{customParams?.map((paramsName: ParametersType, i: any) => (
<Flex
Expand Down
2 changes: 1 addition & 1 deletion src/components/inspector/panels/styles/DimensionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const DimensionPanel = () => {
<TextControl label="Max H" name="maxHeight" />
</SimpleGrid>

<FormControl label="Overflow">
<FormControl label="Overflow" htmlFor="overflow">
<Select
size="sm"
value={overflow || ''}
Expand Down
2 changes: 1 addition & 1 deletion src/components/inspector/panels/styles/DisplayPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const DisplayPanel = () => {

return (
<>
<FormControl label="Display">
<FormControl label="Display" htmlFor="display">
<Select
size="sm"
value={display || ''}
Expand Down
2 changes: 1 addition & 1 deletion src/components/inspector/panels/styles/EffectsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const EffectsPanel = () => {

return (
<>
<FormControl label="Opacity">
<FormControl label="Opacity" htmlFor="opacity">
<Slider
min={1}
onChange={(value: any) => setValue('opacity', value / 100)}
Expand Down
6 changes: 3 additions & 3 deletions src/components/inspector/panels/styles/FlexPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const FlexPanel = () => {

return (
<>
<FormControl label="Direction">
<FormControl label="Direction" htmlFor="flexDirection">
<Select
name="flexDirection"
size="sm"
Expand All @@ -27,7 +27,7 @@ const FlexPanel = () => {
</Select>
</FormControl>

<FormControl label="Justify content">
<FormControl label="Justify content" htmlFor="justifyContent">
<Select
name="justifyContent"
size="sm"
Expand All @@ -42,7 +42,7 @@ const FlexPanel = () => {
</Select>
</FormControl>

<FormControl label="Align items">
<FormControl label="Align items" htmlFor="alignItems">
<Select
name="alignItems"
size="sm"
Expand Down
61 changes: 61 additions & 0 deletions src/custom-components/paramSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React from 'react'
import {
Popover,
PopoverTrigger,
PopoverContent,
PopoverHeader,
PopoverBody,
PopoverFooter,
PopoverArrow,
PopoverCloseButton,
PopoverAnchor,
ListIcon,
ListItem,
List,
Portal,
} from '@chakra-ui/react'
import { ChevronLeftIcon } from '@chakra-ui/icons'
import { useSelector } from 'react-redux'
import { getComponentParamNames } from '~core/selectors/components'
import { MdCheckCircle } from 'react-icons/md'
import { IoMdRadioButtonOff } from 'react-icons/io'
import { useForm } from '~hooks/useForm'
import usePropsSelector from '~hooks/usePropsSelector'

const ParamSelector = ({ prop }: any) => {
const params = useSelector(getComponentParamNames)
const { setValue } = useForm()
const value = usePropsSelector(prop)
return (
<span>
<Popover placement="left" trigger="hover">
<PopoverTrigger>
<ChevronLeftIcon />
</PopoverTrigger>
<Portal>
<PopoverContent>
<PopoverArrow />
<PopoverCloseButton />
<PopoverHeader>Select parameter</PopoverHeader>
<PopoverBody>
<List>
{params?.map((param: string) => (
<ListItem
onClick={() => setValue(prop, param)}
key={param}
px={1}
_hover={{ bg: 'teal.100' }}
>
{param}
</ListItem>
))}
</List>
</PopoverBody>
</PopoverContent>
</Portal>
</Popover>
</span>
)
}

export default ParamSelector
1 change: 0 additions & 1 deletion src/pages/api/refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function getComponentWithLocation(path) {

async function getJsons() {
let jsons = {}
// TODO: Change this later to the root without any dependecy on gitpod.yml, BIT or tiui-react-oc
const files = glob.sync(`../remote/**/*.oc.json`, {})
files.forEach(element => {
const { comp, dir } = getComponentWithLocation(element)
Expand Down
Loading

0 comments on commit 365d58e

Please sign in to comment.