Draft: Resolve #3462310 "Component edit"
Closes #3462310
Merge request reports
Activity
13 14 'drupal-form--xbxb': Form, 14 15 'drupal-form-element--xbxb': FormElement, 15 16 'drupal-form-element-label--xbxb': FormElementLabel, 17 select: SelectComponent, I tried mapping the component
drupal-select--xbxbanddrupal-form-element-select--xbxbwith the select element that i created but it does not load the component. It only load withselect: SelectComponent,. The problem must be related to how hyperscriptify works.Is there something that i might be missing as a part of mapping the select element?changed this line in version 4 of the diff
- ui/src/components/form/Select.tsx 0 → 100644
1 import type * as React from 'react'; Had a discussion with @jessebaker regarding this that we need to use the select component form the Radix library.For now i have added the code with basic structure which can be further fine-tuned as we move forward.
added 2 commits
13 14 'drupal-form--xbxb': Form, 14 15 'drupal-form-element--xbxb': FormElement, 15 16 'drupal-form-element-label--xbxb': FormElementLabel, 17 'drupal-select--xbxb': SelectComponent, - ui/src/components/form/Select.tsx 0 → 100644
16 17 const SelectComponent: React.FC<SelectComponentProps> = ({ 18 options, 19 initialSelection = '', 20 }) => { 21 const [selectedValue, setSelectedValue] = useState(initialSelection); 22 23 return ( 24 <div> 25 <Select.Root 26 value={selectedValue} 27 onValueChange={(value) => setSelectedValue(value)} 28 > 29 <Select.Trigger className={clsx('selectTrigger')} /> 30 <Select.Content className={clsx('selectContent')}> 31 {/*<Select.Group>*/} changed this line in version 7 of the diff
added 10 commits
-
4dd9794f...a8ead8ae - 3 commits from branch
project:0.x - 9dc9a871 - Rebasing
- 565848d9 - Added styling for input and label elements
- 7d2cc38a - Added select component and it's styling
- 3d262c85 - Removed unwanted code
- 0fd2b3ca - Wip for link component
- 4223f6bf - Added drupal-select--xbxb for mapping
- 7970bb62 - Removed linkElement
Toggle commit list-
4dd9794f...a8ead8ae - 3 commits from branch
added 2 commits
added 18 commits
-
9a48986e...212b5fa3 - 3 commits from branch
project:0.x - 212b5fa3...2d70e8b4 - 5 earlier commits
- a4d593be - Added drupal-select--xbxb for mapping
- adc142ab - Removed linkElement
- fc006002 - Added custom select component close to figma designs
- 87b61640 - Prettier
- 40f1dba1 - Added inline styles
- 802237c9 - Removed imports and fixed styleLint
- 2bbc054a - fixed styleLint
- 53c4abff - Added empty link element and mapped the element
- c588ac76 - Renamed link--xbxb to links--xbxb
- d37a1ad4 - Stylelint
Toggle commit list-
9a48986e...212b5fa3 - 3 commits from branch
added 1 commit
- 59f3a153 - Conditionally rendered link element inside input element
13 15 'drupal-form--xbxb': Form, 14 16 'drupal-form-element--xbxb': FormElement, 15 17 'drupal-form-element-label--xbxb': FormElementLabel, 18 'drupal-select--xbxb': SelectComponent, 19 'drupal-links--xbxb': Links, This won't work as we are not processing the link element seperately but it's processed as a part of input.tsx where i have added a if condition that if
props.attributes.type === 'url'then return a distinguishing markup for link element. We can see that in theDummyPropsForm.I am not sure what and how we need to distinguish between the link and input component.
When you reference
DummyPropsFormcan you also mention what component is being edited? The contents can be a vastly different depending on the component type so not knowing it makes it very difficult to know what is being referenced.I'm also not entirely sure what is meant by
but it's processed as a part of input.tsbut if that but as mentioned in another comment, Links and inputs are separate templates, you do not need to account for one in the other. The input template renders children, and links can be one of those children, but it doesn't need to do anything special for it. This may be an issue of not having the props fully set up in links--xbxb-html.twig
6 6 const Input = (props: React.ComponentProps<any>) => { 7 7 const { attributes = {}, renderChildren = '' } = props; 8 8 const unHandledTypes = ['submit', 'hidden']; 9 if (props.attributes.type === 'url') { 10 return ( - templates/form/links--xbxb.html.twig 0 → 100644
1 { Based on the variables list in links.html.twig, it seems like there should be more depth to this configuration. This determines what gets sent as props, and what data type is expected. For example within links there are sub-properties that will likely be different data types `* - links: Links to be output.
- Each link will have the following elements:
-
- link: (optional) A render array that returns a link. See
-
template_preprocess_links() for details how it is generated. -
- text: The link text.
-
- attributes: HTML attributes for the list item element.
-
- text_attributes: (optional) HTML attributes for the span element if no
-
'url' was supplied.`
If you're unsure what props to set up, a breakpoint at the end of
semi_coupled_themecan help too.return $renderer->render($element);
- ui/src/components/form/Links.tsx 0 → 100644
1 import type React from 'react'; Once the doubt asked in !162 (comment 358657) gets clarified we can add the markup here to render the link elements.
- templates/form/links--xbxb.html.twig 0 → 100644
1 { 2 "props": { 3 "attributes": "object", 4 "links": "array", 5 "heading": "object | string" - templates/form/links--xbxb.html.twig 0 → 100644
9 if (props.attributes.type === 'url') { 10 return ( 11 <div className="link-input-container"> 12 <input type="text" className="link-input" placeholder="🔗Add" /> 13 </div> 14 ); 15 } 9 16 10 17 return ( 11 18 <> 12 19 {!unHandledTypes.includes(attributes?.type) && ( 13 <TextField.Root {...a2p(attributes)} mb="5" /> 20 <TextField.Root 21 {...a2p(attributes)} 22 mb="5" 23 style={{ - ui/src/components/form/Links.tsx 0 → 100644
1 import type React from 'react'; 2 3 interface LinkProps { 4 links: Array<{ 5 text: string; 6 url?: string; 7 icon?: JSX.Element; Where is this
iconproperty coming from? That doesn't seem to match the template variables documented in the twig version ` * Each link will have the following elements:-
- link: (optional) A render array that returns a link. See
-
template_preprocess_links() for details how it is generated. -
- text: The link text.
-
- attributes: HTML attributes for the list item element.
-
- text_attributes: (optional) HTML attributes for the span element if no
-
'url' was supplied.`
-
- ui/src/components/form/Select.tsx 0 → 100644
50 className="SelectItem" 51 disabled={option.disabled} 52 > 53 {option.label} 54 </Select.Item> 55 ))} 56 </> 57 )} 58 </Select.Group> 59 </Select.Content> 60 </Select.Root> 61 </div> 62 ); 63 }; 64 65 export default SelectComponent; If you look at the existing components, you'll notice the export is wrapped in
InputBehaviorsFor example
export default inputBehaviors(Input);this is what makes it possible to manage values at the form level instead of the component level and update redux without having to add handlers to every new component.
- ui/src/components/form/Select.tsx 0 → 100644
18 initialSelection?: string; 19 } 20 21 const SelectComponent: React.FC<SelectComponentProps> = ({ 22 attributes, 23 options, 24 renderOptions, 25 initialSelection = 'none', 26 }) => { 27 const [selectedValue, setSelectedValue] = useState(initialSelection); 28 29 return ( 30 <div className="SelectWrapperDiv"> 31 <Select.Root 32 value={selectedValue} 33 onValueChange={(value) => setSelectedValue(value)} - Comment on lines +27 to +33
- ui/src/components/form/Select.tsx 0 → 100644
26 }) => { 27 const [selectedValue, setSelectedValue] = useState(initialSelection); 28 29 return ( 30 <div className="SelectWrapperDiv"> 31 <Select.Root 32 value={selectedValue} 33 onValueChange={(value) => setSelectedValue(value)} 34 {...a2p(attributes)} 35 > 36 <Select.Trigger className={clsx('selectTrigger')}> 37 {selectedValue || 'Select an option'} 38 </Select.Trigger> 39 <Select.Content className={clsx('selectContent')}> 40 <Select.Group> 41 {renderOptions ? ( - ui/src/components/form/select.css 0 → 100644
I think it would be great to leverage design tokens from Radix Themes in the form of CSS variables. A few examples:
- Instead of defining the paddings or the gap in pixels, let's use space scale tokens;
- The border radius can use the radius scale;
- Any color should probably use a color token.
We may need to customize the Theme component to tweak some of the values. I think it's also a good idea to keep in mind that if we end up with a lot of CSS overrides, we should probably be using the unstyled Radix Primitive rather than the component from Radix Theme. Also when adding wrappers only for layout, let's use
Box,Flexetc, so we can avoid adding paddings, margin etc. with custom CSS.
Closing this in favor of !188 (merged).