Skip to content

Commit

Permalink
docs(site): join composition guides. remove layouts (#1727)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusps authored Jul 16, 2024
2 parents fb4a8e0 + aac1480 commit c86d66b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 40 deletions.
1 change: 0 additions & 1 deletion packages/docs/pages/guides/_meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"getting-started": "Getting Started",
"layouts": "Layouts",
"state-management": "State Management",
"styling": "Styling",
"composition": "Composition",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Composition

Sometimes it might be necessary to use the behaviour of a component on another one. For example you might need a button to behave as a link, or you might want a `div` with some component's functionality. Composable components are made to enable that.

In Shoreline the concept of "composable" components are those that support a boolean property called `asChild`. When set to `true`, this property enables the component to extend its behavior to its child components. That allows the component to keep it's original features, but render as something different.

## Extending Component Behavior

Composable components, by definition, possess a prop named `asChild`. When this property is set to `true`, it alters the behavior of the component. Instead of rendering in the usual manner, it renders its `children` and injects its internal props into them.
Expand Down Expand Up @@ -35,6 +41,31 @@ function ComposabilityExample() {
}
```

## Requirements for Child Components

To be cloned and extended, custom components must be extensible. All components in Shoreline adhere to this requirement and can be used as children for composable components. The criteria for a component to be extensible include:

1. Forward a Ref: Components need to forward a [ref](https://react.dev/reference/react/forwardRef).
2. Forward Received Props: Components must forward the props they receive.

### Extensible Component Example

Here is an example of an extensible component:

```
const CustomComponent = forwardRef((props, ref) => {
const { name, ...otherProps } = props
return (
<div {...otherProps} ref={ref}>
{name}
</div>
)
})
```

This component successfully forwards a ref and ensures that all received props are also forwarded. This adherence to extensibility makes it compatible as a child for composable components in the Shoreline library.

## Availability in Shoreline

### Not all components are composable
Expand Down
5 changes: 0 additions & 5 deletions packages/docs/pages/guides/composition/_meta.json

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions packages/docs/pages/guides/composition/introduction.mdx

This file was deleted.

5 changes: 0 additions & 5 deletions packages/docs/pages/guides/layouts.mdx

This file was deleted.

0 comments on commit c86d66b

Please sign in to comment.