import { Meta } from '@storybook/addon-docs'; import { parameters } from '$docs/utils/docsPage.js';  # Component guidelines ## Dependencies Components should be written for any Svelte context. If your component needs, for example, values from SvelteKit stores, these should be passed in as props. ## Typescript By default, component's are written in TypeScript, which adds robust type-checking and helpful hints for people using your component in editors like Visual Studio Code. > If you've never used TypeScript, you can check out the [5-minute intro](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html). If you're still uneasy writing TypeScript, don't sweat it! Just write your component in plain JavaScript/Svelte. We'll convert at least your component's props to TypeScript as part of the PR review. ### Typing and documenting component props Document props using [JSDoc comments](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html) (be sure to mark required props) and type props with TypeScript. Here are a few examples: #### Typing simple props ```svelte ``` #### Documenting required props ```svelte ``` #### Custom types for props ```svelte ``` #### Future syntax Using some future syntax like [optional chaining](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) in your components currently breaks the automatic discovery of JSDoc comments in your component, which are used to fill in the [ArgsTable](https://storybook.js.org/docs/react/writing-docs/doc-block-argstable). So instead of... ```javascript myObject?.myOptionalProp; ``` ...unfortunately, use something old-fashioned like... ```javascript myObject.myOptionalProp ? myObject.myOptionalProp : null; ``` If your component docs still aren't working, check if you're using other future-JS sytax, for now. ## Styles ### Theming Always respect styles set by the [`Theme`](/?path=/docs/theming-theme--default) component by using [CSS variables](?path=/docs/scss-css-variables--page) where they apply to your component. Always set [fallback values](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties#custom_property_fallback_values) for the default light theme. ### SCSS Use SCSS with the `lang` attribute to write your styles. ```svelte ``` ### Scope Styles should **always** be scoped to your components. ```svelte ``` In rare cases, you can use the SCSS `:global` operator to style child elements in your component, but those rules should still be scoped below a parent element. ```svelte ``` ### CSS variables Use [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) and props to allow better theming of your components. ```svelte
My text.