Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
experience_builder
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
experience_builder
Commits
bd499944
Commit
bd499944
authored
1 week ago
by
Bálint Kléri
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3515903
by balintbrews, lauriii, gábor hojtsy: Add starter code for code components
parent
6ae3a811
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!826
#3515903: Add starter code for code components
Pipeline
#459483
failed
1 week ago
Stage: development
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ui/src/features/code-editor/dialogs/AddCodeComponentDialog.tsx
+2
-1
2 additions, 1 deletion
...c/features/code-editor/dialogs/AddCodeComponentDialog.tsx
ui/src/features/code-editor/starterComponentTemplate.ts
+53
-0
53 additions, 0 deletions
ui/src/features/code-editor/starterComponentTemplate.ts
with
55 additions
and
1 deletion
ui/src/features/code-editor/dialogs/AddCodeComponentDialog.tsx
+
2
−
1
View file @
bd499944
...
...
@@ -9,6 +9,7 @@ import {
}
from
'
@/features/ui/codeComponentDialogSlice
'
;
import
Dialog
,
{
DialogFieldLabel
}
from
'
@/components/Dialog
'
;
import
{
setName
}
from
'
@/features/code-editor/codeEditorSlice
'
;
import
getStarterComponentTemplate
from
'
@/features/code-editor/starterComponentTemplate
'
;
const
AddCodeComponentDialog
=
()
=>
{
const
[
componentName
,
setComponentName
]
=
useState
(
''
);
...
...
@@ -27,7 +28,7 @@ const AddCodeComponentDialog = () => {
// Mark this code component as "internal": do not make it available to Content Creators yet.
// @see docs/config-management.md, section 3.2.1
status
:
false
,
source_code_js
:
''
,
source_code_js
:
getStarterComponentTemplate
(
componentName
)
,
source_code_css
:
''
,
compiled_js
:
''
,
compiled_css
:
''
,
...
...
This diff is collapsed.
Click to expand it.
ui/src/features/code-editor/starterComponentTemplate.ts
0 → 100644
+
53
−
0
View file @
bd499944
import
{
camelCase
}
from
'
lodash
'
;
export
default
function
getStarterComponentTemplate
(
componentName
:
string
)
{
const
camelCased
=
camelCase
(
componentName
);
const
variableName
=
camelCased
.
charAt
(
0
).
toUpperCase
()
+
camelCased
.
slice
(
1
);
return
`// Use Preact (https://preactjs.com) and Tailwind CSS 4 (https://tailwindcss.com).
// Global CSS is added to all pages with a @theme directive.
// Tailwind theme variables must be added in Global CSS.
// @see https://tailwindcss.com/docs/theme.
// Do not include @import "tailwindcss"!
// Available third party packages:
// import { clsx } from 'clsx'
// import { cva } from 'class-variance-authority'
// import { twMerge } from 'tailwind-merge'
//
// Combine classes with the cn() utility function.
// @see https://git.drupalcode.org/project/experience_builder/-/blob/0.x/ui/lib/astro-hydration/src/lib/utils.ts
import { cn } from "@/lib/utils";
const
${
variableName
}
= ({
// List component props and slots here. To expose them on the UI, add them
// under "Component data".
// The camelCased prop/slot name must match the argument name here
// (eg. "Card variant" → "cardVariant").
title = "
${
componentName
}
",
}) => {
return (
<div className="max-w-sm min-h-36 p-2 font-bold rounded-lg text-2xl relative mx-auto flex items-center justify-center bg-[#ffc423] text-[#12285f]">
<ControlDots className="top-4 left-4 stroke-white absolute" />
{title}
</div>
);
};
export default
${
variableName
}
;
const ControlDots = ({ className }) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 31 9"
fill="none"
strokeWidth="2"
className={cn("w-12", className)}
>
<ellipse cx="4.13" cy="4.97" rx="3.13" ry="2.97" />
<ellipse cx="15.16" cy="4.97" rx="3.13" ry="2.97" />
<ellipse cx="26.19" cy="4.97" rx="3.13" ry="2.97" />
</svg>
);
`
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment