Skip to content

Feature/add design system - #1

Draft
Ania-chan wants to merge 17 commits into
mainfrom
feature/add-design-system
Draft

Feature/add design system#1
Ania-chan wants to merge 17 commits into
mainfrom
feature/add-design-system

Conversation

@Ania-chan

@Ania-chan Ania-chan commented Dec 19, 2023

Copy link
Copy Markdown
Owner

Description:

  • add colour theme
  • add Button component
  • add NumberInput component
  • add MessageBubble component
  • add NameGenerator component
  • add TextArea component
  • add Icon component

@Ania-chan
Ania-chan marked this pull request as draft December 19, 2023 10:49
@Ania-chan Ania-chan self-assigned this Dec 19, 2023
Comment thread src/components/NumberInput/NumberInput.js Outdated
Comment thread src/components/Button/Button.js Outdated
const { button } = van.tags

export const Button = ({ text, onClick, type }) =>
button({ onclick: onClick, class: `button ${type || 'default'}` }, text)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Ania-chan Personally, I would add optional parameters to the function for disabled and value attributes, as well as name and an alt description.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@zr0z I added these params except for value. What do you mean by this? There is already a text passed to this component

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Ania-chan by default button is assumed to act on a form, so the behavior of the button should be in a value property and it will be sent to the server alongside the name.

If you assume that your component will never be used within a form then it should have a type set to button.

From MDN:

If your buttons are not for submitting form data to a server, be sure to set their type attribute to button. Otherwise they will try to submit form data and to load the (nonexistent) response, possibly destroying the current state of the document.

Comment thread src/components/NameGenerator/NameGenerator.js Outdated

const { img } = van.tags

export const Icon = ({ name, alt = '' }) => img({ class: 'icon', alt, innerHTML: icons[name] })

@zr0z zr0z Jan 30, 2024

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Ania-chan The <img> tag should always have a source and it is not supposed to have children nodes.

So you can't use innerHTML here, you could if you were rather using an <object> tag.

With the required src you can display SVG content either by passing the URL of the file, or by using a data URI. You will have to use the javascript function to encode the SVGs before passing it to src.

data:image/svg+xml;charset=UTF-8,[URL encoded SVG code]

The last issue is that icons[name] is actually a promise, so it would needs to be awaited.
For simplicity sake, VanJS is using synchronous component so you would need to use a state to display the icon when it has been awaited.

Finally, as a alt I would personally use ${name} icon and not expose it as a parameter, even better if you add a capitalize function.

logo: () => import('./icons/Logo.svg')
}

export default icons

@zr0z zr0z Jan 30, 2024

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Personally I would export an async function taking the icon name rather than exposing the data structure in which you store the data.
If you decide in the future to change the way you are structuring the data you only have to modify the implementation of that file rather than going through all the other files and changing there.

export default async function (name) {
  return icons[name];
}

Related to the issue highlighted above and due to the fact that we only have three icons, I would rather just import them without lazy loading.

import copy from './icons/Copy.svg?raw';
...

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.

2 participants