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

Document our coding conventions to ease contributing and consistency #2450

Open
eirikbacker opened this issue Sep 18, 2024 · 1 comment
Open
Labels
documentation/code For documentation related to code and technical specifications

Comments

@eirikbacker
Copy link
Contributor

eirikbacker commented Sep 18, 2024

To make it easier to contribute and for ourselves to have a consistent codebase, we should document some of our coding conventions.

  • Always provide ref through forwardRef (unless exposing a Context)
  • Always check props naming conventions on other components for consistency
  • Add all HTML props through React.{TagName}HTMLAttributes<HTML{TagName}Element>
  • Add the HTML attributes on the outermost element
  • Avoid custom use of native HTML attributes (i.e. className should always work as expected)
  • Avoid invalid states (i.e. both successText and errorText at the same time)
  • Avoid creating multiple components when they can be just variant or compound with same functionality
  • Use useId() when if needed for accessibility
  • Use @media(hover: hover) and (pointer: fine) around :hover to avoid :hover on touch-devices
  • Use compound components pattern instead of many props on single component
  • Use lowercase boolean props (i.e. hidden instead of isHidden)
  • Use :focus-visible to style focus state
  • Use ReactNode type for props instead of string (unless it has to be string)
  • Use useEffect if manipulating DOM directly to ensure server compatibility
  • Use Component as name of the outermost HTML element rendering the component
  • Use Component.Context as a wrapper (and Component.Trigger) if a component has context and trigger
  • Use Context as name of internal, non-exposed Context
  • Use import of specific React typescript types, instead of depending on global React.*
  • Use Component.List when listing multiple items
  • Use background and not background-color in tokens to allow setting advanced values like linear-gradient
  • Use &:not([hidden]) { display: } around display to support hidden attribute
@eirikbacker eirikbacker converted this from a draft issue Sep 18, 2024
@eirikbacker eirikbacker added the documentation/code For documentation related to code and technical specifications label Sep 18, 2024
@mimarz
Copy link
Collaborator

mimarz commented Oct 17, 2024

Some additions:

  • Use --dsc prefix for component tokens/variables
  • Use css property name in component tokens its applied to (ie --dsc-button-padding-block)

Barsnes added a commit that referenced this issue Jan 8, 2025
- Respect `hidden` attribute on all components
- Updated #2450
- Did not fix tabs as this is fixed in
#2944

---------

Co-authored-by: Barsnes <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation/code For documentation related to code and technical specifications
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants