¥Styling
Radix Primitives 无需样式,并且兼容任何样式解决方案,让你可以完全控制样式。
¥Styling overview
¥Functional styles
你可以控制样式的各个方面,包括功能性样式。例如,默认情况下,对话框覆盖 不会覆盖整个视口。你负责添加这些样式以及任何演示样式。
¥You are in control of all aspects of styling, including functional styles. For example—by default—a Dialog Overlay won't cover the entire viewport. You're responsible for adding those styles, plus any presentation styles.
¥Classes
所有组件及其组件都接受 className
prop。此类将传递给 DOM 元素。你可以按预期在 CSS 中使用它。
¥All components and their parts accept a className
prop. This class will be passed through to the DOM element. You can use it in CSS as expected.
¥Data attributes
当组件有状态时,其状态将在 data-state
属性中公开。例如,打开 手风琴项目 时,它包含一个 data-state="open"
属性。
¥When components are stateful, their state will be exposed in a data-state
attribute. For example, when an Accordion Item is opened, it includes a data-state="open"
attribute.
¥Styling with CSS
¥Styling a part
你可以通过定位你提供的 className
来设置组件部分的样式。
¥You can style a component part by targeting the className
that you provide.
¥Styling a state
你可以通过定位组件的 data-state
属性来设置其状态样式。
¥You can style a component state by targeting its data-state
attribute.
¥Styling with CSS-in-JS
下面的示例使用的是 styled-components,但你可以使用任何你选择的 CSS-in-JS 库。
¥The examples below are using styled-components, but you can use any CSS-in-JS library of your choice.
¥Styling a part
大多数 CSS-in-JS 库都导出一个用于传递组件及其样式的函数。你可以直接提供 Radix 基础组件组件。
¥Most CSS-in-JS libraries export a function for passing components and their styles. You can provide the Radix primitive component directly.
¥Styling a state
你可以通过定位组件的 data-state
属性来设置其状态样式。
¥You can style a component state by targeting its data-state
attribute.
¥Extending a primitive
扩展基础组件的方式与扩展任何 React 组件的方式相同。
¥Extending a primitive is done the same way you extend any React component.
¥Summary
Radix Primitives 旨在封装可访问性问题和其他复杂功能,同时确保你完全掌控样式。
¥Radix Primitives were designed to encapsulate accessibility concerns and other complex functionalities, while ensuring you retain complete control over styling.
为方便起见,有状态组件包含 data-state
属性。
¥For convenience, stateful components include a data-state
attribute.