Skip to content

New components#1

Merged
smnh merged 23 commits intomainfrom
new-components
Aug 3, 2021
Merged

New components#1
smnh merged 23 commits intomainfrom
new-components

Conversation

@smnh
Copy link
Copy Markdown
Contributor

@smnh smnh commented Jul 21, 2021

@netlify
Copy link
Copy Markdown

netlify bot commented Jul 21, 2021

✔️ Deploy Preview for stackbit-components ready!

🔨 Explore the source changes: 84cd131

🔍 Inspect the deploy log: https://app.netlify.com/sites/stackbit-components/deploys/6109d0a779b42200079dfb8f

😎 Browse the preview: https://deploy-preview-1--stackbit-components.netlify.app

@smnh smnh marked this pull request as draft July 21, 2021 16:52
@smnh
Copy link
Copy Markdown
Contributor Author

smnh commented Jul 21, 2021

@TomasBankauskas good start!
Here is some feedback.

The hero section have 4 variants, but they all look the same. For example the variant-c and variant-d has the exact same code. The difference is that one has image and the other has video. For these differences we want to use atomic components rather having different variants. Otherwise, the component will be bloated with lots of fields not related to one another like imageUrl, imageAlt, videoUrl, etc. Variants should really change the whole appearance of the section not of specific item in the section.

For example, to have a hero section with image or video, you can have a field feature that can be an image or video model. These models in turn will have URL for image or video, alt text, and anything else these specific components need.

fields:
  - type: string
    name: title
  - type: string
    name: subtitle
  - type: model
    name: feature
    models: [image, video]

The hero section has both variant and mediaPosition. This kinda kills the purpose of variants. You should have either first or the second.

Consider renaming style to colors

Copy link
Copy Markdown
Contributor Author

@smnh smnh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomasBankauskas good work! 👍
I've commented here on some thing that we need to improve, but you can already merge it.

Comment thread src/components/hero-section/index.js Outdated
Comment on lines +48 to +49
case 'variant-e':
return HeroNoFeature(props);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomasBankauskas I think there is no need in variant-e. Because in any variant if the feature object is not set, then it will be the same as HeroNoFeature.
You can check here if the feature is not set, then you can render HeroNoFeature and remove variant-e fomt he model

Comment thread src/components/hero-section/index.js Outdated
Comment on lines +120 to +122
if (!feature) {
return null;
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomasBankauskas returning null here is too late. Because you will get an empty div:

<div className="mt-8 lg:mt-12">
</div>

Comment thread src/components/hero-section/index.js Outdated
'max-w-screen-xl': width === 'wide',
'max-w-screen-lg': width === 'narrow',
'min-h-screen flex flex-col justify-center': height === 'viewport',
'text-center': alignHoriz === 'center'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be ok if we add alignment "right"?

Comment thread src/components/hero-section/index.js Outdated
{props.badge && <Badge label={props.badge} />}
{props.title && (
<h1 className="font-medium font-sans text-4xl tracking-tight sm:text-5xl mb-6">
<ReactMarkdown allowedElements={['br', 'span', 'strong']} unwrapDisallowed={true} components={components}>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allowedElements might be too limited, what about italics (*italics*) or links ([link](https://...))?
Let's use markdown-to-jsx. There is also an option forceInline which will ensure that it will not try to wrap it with block elements like <p> or <h1>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P.S.:
This can wait for next iteration

Comment on lines +18 to +20
'mx-auto': width !== 'full',
'max-w-screen-xl': width === 'wide',
'max-w-screen-lg': width === 'narrow',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomasBankauskas this code snippet is used in 6 places.
Is it possible to make it a utility function, or even better, remap it to a new utility style like section-w-full, section-w-wide, section-w-narrow?
To make it easier for developers to update style via tailwind.config.js rather cloning and customizing all components.

'mx-auto': width !== 'full',
'max-w-screen-xl': width === 'wide',
'max-w-screen-lg': width === 'narrow',
'min-h-screen flex flex-col justify-center': height === 'viewport',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this one, can we create a utility class section-h-viewport? This way developers will be able to customize all section heights without customizing all sections.

Comment thread src/components/contact-section/index.js Outdated
Comment on lines +55 to +62
<div
className="w-full lg:inset-y-0 lg:w-1/2 lg:max-w-full lg:absolute right-0 lg:pl-4">
<img
src={props.imageUrl}
className="w-screen max-w-none ml-1/2 transform -translate-x-1/2 object-cover lg:h-full lg:ml-0 lg:transform-none lg:w-full lg:max-w-full"
alt={props.imageAltText}
/>
</div>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using ImageBlock here. Even if it is the only possible type for this section.

Comment on lines +123 to +128
switch (feature.type) {
case 'image_block':
return <ImageBlock {...feature} className={classNames({ 'mx-auto': alignHoriz === 'center' })} />;
case 'video_block':
return <VideoBlock {...feature} />;
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike the variants which are constant, types that can be embedded into Hero section are dynamic.

Component Categories:

fields:
  - type: model
    name: feature
    label: Feature
    categories: [hero_block]

That means that feature field can container any model, not only image_block or video_block.
Therefore, the code should be similar to how it works in Advanced layout:

const Component = components[sectionType];
return <Component {...feature} />;

Note: the models YAML don't support categories yet.

Comment on lines 6 to +10
export default function Button({ label, url, icon, alt, className }) {
const iconMap = {
arrowRight: ArrowRight,
cart: Cart
};
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we support button primary anymore?
How would user be able to change button from primary to secondary without changing the style of the whole section?

Comment on lines +153 to +155
switch (field.inputType) {
case 'checkbox':
return (
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the form controls should be separates into separate components, each with their own type.
And the form would have a list of fields models categorized as "form-field".
Then developer will be able to create new types of "form-fields":

const Component = components[field.type];
return <Component {...field} />;

Comment on lines +88 to +107
'.colors-a': {
backgroundColor: theme('colors.base-50'),
color: theme('colors.base-900'),
'input,textarea,select,hr': {
borderColor: theme('colors.base-900')
},
'::placeholder': {
color: theme('colors.base-900')
},
'.sb-btn': {
backgroundColor: theme('colors.primary'),
color: theme('colors.base-900'),
'&:hover': {
backgroundColor: theme('colors.primary-variant')
},
},
'.sb-card': {
backgroundColor: theme('colors.secondary')
}
},
Copy link
Copy Markdown
Contributor Author

@smnh smnh Aug 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TomasBankauskas is there a way to define flat object with colors and apply them to components like in DaisyUI?
In DaisyUI, they use it for themes, so each theme has a flat object with different set of colors that is applied everywhere else.
https://github.com/saadeghi/daisyui/blob/master/src/colors/themes.js#L2-L23
Then buttons assigned base text colors and background colors:
https://github.com/saadeghi/daisyui/blob/master/src/components/styled/button.css#L26-L56

TomasBankauskas and others added 3 commits August 2, 2021 16:58
- added dynamic/imports
- moved models to root folder
@smnh smnh marked this pull request as ready for review August 3, 2021 23:28
@smnh smnh merged commit 2c8d43c into main Aug 3, 2021
@smnh smnh deleted the new-components branch August 3, 2021 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants