Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stack plugin #1276

Merged
merged 7 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "StackPluginConfig",
"type": "dmss://system/SIMOS/Blueprint",
"attributes": [
{
"name": "type",
"type": "CORE:BlueprintAttribute",
"attributeType": "string"
},
{
"name": "items",
"type": "CORE:BlueprintAttribute",
"attributeType": "CORE:ViewConfig",
"dimensions": "*"
},
{
"name": "direction",
"type": "CORE:BlueprintAttribute",
"description": "horizontal or vertical",
"attributeType": "string",
"optional": true,
"default": "vertical"
},
{
"name": "horizontalPlacement",
"type": "CORE:BlueprintAttribute",
"description": "left, center, right or spaceItems",
awesthouse marked this conversation as resolved.
Show resolved Hide resolved
"attributeType": "string",
awesthouse marked this conversation as resolved.
Show resolved Hide resolved
"optional": true,
"default": "left"
},
{
"name": "verticalPlacement",
"type": "CORE:BlueprintAttribute",
"description": "top, center or bottom",
"attributeType": "string",
awesthouse marked this conversation as resolved.
Show resolved Hide resolved
"optional": true,
"default": "top"
},
{
"name": "spacing",
"type": "CORE:BlueprintAttribute",
"description": "REM value. Default is 2 = 32px",
pbullhove marked this conversation as resolved.
Show resolved Hide resolved
"attributeType": "number",
"optional": true,
"default": 2
},
{
"name": "maxWidth",
"type": "CORE:BlueprintAttribute",
"description": "Set max-width of wrapper if you want to use less than 100% width.",
"attributeType": "string",
"optional": true
},
{
"name": "wrapItems",
"type": "CORE:BlueprintAttribute",
"description": "When using horizontal direction, make items wrap under eachother when width is getting too small to fit all items",
"attributeType": "boolean",
"optional": true,
"default": false
},
{
"name": "classNames",
"type": "CORE:BlueprintAttribute",
"description": "Add tailwind classNames to wrapper",
"attributeType": "string",
"dimensions": "*",
"optional": true
}
]
}
25 changes: 25 additions & 0 deletions packages/dm-core-plugins/blueprints/stack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "stack",
"type": "CORE:Package",
"isRoot": false,
"_meta_": {
"type": "CORE:Meta",
"version": "0.0.1",
"dependencies": [
{
"type": "CORE:Dependency",
"alias": "CORE",
"address": "system/SIMOS",
"version": "0.0.1",
"protocol": "dmss"
},
{
"type": "CORE:Dependency",
"alias": "PLUGINS",
"address": "system/Plugins",
"version": "0.0.1",
"protocol": "dmss"
}
]
}
}
7 changes: 7 additions & 0 deletions packages/dm-core-plugins/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export default ({
}))
),
},
'@development-framework/dm-core-plugins/stack': {
component: lazy(() =>
import('./stack/StackPlugin').then((module) => ({
default: module.StackPlugin,
}))
),
},
'@development-framework/dm-core-plugins/data_grid': {
component: lazy(() =>
import('./data-grid/DataGridPlugin').then((module) => ({
Expand Down
51 changes: 51 additions & 0 deletions packages/dm-core-plugins/src/stack/StackPlugin.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { IUIPlugin, Stack, ViewCreator } from '@development-framework/dm-core'
import {
DirectionTypes,
StackProps,
} from '@development-framework/dm-core/dist/components/common/Stack/types'
import { StackPluginConfig, defaultConfig } from './types'

export const StackPlugin = (props: IUIPlugin) => {
const { idReference } = props
const config: StackPluginConfig = { ...defaultConfig, ...props.config }

// map plugin language to stack props/css language
const configMap: { [name: string]: string } = {
vertical: 'column',
horizontal: 'row',
horizontalPlacement:
config.direction === 'horizontal' ? 'alignItems' : 'justifyContent',
verticalPlacement:
config.direction === 'horizontal' ? 'justifyContent' : 'alignItems',
left: 'flex-start',
center: 'center',
right: 'flex-end',
top: 'flex-start',
bottom: 'flex-end',
spaceItems: 'space-between',
}

const stackProps: StackProps = {
direction: configMap[config.direction] as DirectionTypes,
[configMap.verticalPlacement]: configMap[config.verticalPlacement],
[configMap.horizontalPlacement]: configMap[config.horizontalPlacement],
className: config.classNames?.join(' '),
spacing: config.spacing,
wrap: config.wrap ? 'wrap' : 'no-wrap',
style: { maxWidth: config.maxWidth },
}

return (
<Stack {...stackProps}>
{config.items?.map((item, index) => (
<ViewCreator
key={`${item.recipe}_${index}`}
idReference={idReference}
viewConfig={item}
onSubmit={props.onSubmit}
onChange={props.onChange}
/>
))}
</Stack>
)
}
23 changes: 23 additions & 0 deletions packages/dm-core-plugins/src/stack/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { TViewConfig } from '@development-framework/dm-core'

export type StackPluginConfig = {
items: TViewConfig[]
direction: 'horizontal' | 'vertical'
horizontalPlacement: 'left' | 'center' | 'right' | 'spaceItems'
verticalPlacement: 'top' | 'center' | 'bottom'
spacing: number
maxWidth: string
wrap: boolean
classNames: string[]
}

export const defaultConfig: StackPluginConfig = {
items: [],
direction: 'vertical',
horizontalPlacement: 'left',
verticalPlacement: 'top',
spacing: 2,
maxWidth: 'none',
wrap: false,
classNames: [],
}
2 changes: 1 addition & 1 deletion packages/dm-core/src/components/common/Stack/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface StackProps extends React.ComponentPropsWithoutRef<'div'> {
| 'max-content'
grow?: number
shrink?: number
direction?: 'row' | 'column' | 'row-reverse' | 'column-reverse'
direction?: DirectionTypes
wrap?: 'initial' | 'no-wrap' | 'wrap' | 'wrap-reverse'
order?: number
className?: string
Expand Down
1 change: 1 addition & 0 deletions packages/dm-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export type TViewConfig = {
eds_icon?: string
roles?: string[]
showRefreshButton?: boolean
recipe?: string | TUiRecipe
}

export type TReferenceViewConfig = TViewConfig & {
Expand Down
Loading