> For the complete documentation index, see [llms.txt](https://atomico.gitbook.io/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://atomico.gitbook.io/doc/espanol/guias/sistemas-de-diseno/slots.md).

# Slots

El uso de slots mejora la composición permitiéndote reflejar el contenido expuesto en el `lightDOM` del componente en el `shadowDOM` de este, ejemplo:

![](/files/-MbXmejbSIl8PkxrQd24)

### ::slotted(\<selector>)

El selector `slotted` permite la manipulación del contenido expuesto como slot del lightDOM desde el shadowDOM, ejemplo:

![](/files/-MbXpfOBQonGJQg5QVl5)

### Auto slot

Con Atomico puedes definir un slot por defecto para tus componentes, esto es útil si buscas mantener cierta consistencia de composición sin la necesidad de declarar el uso de slot, ejemplo:

```markup
<my-component>
    <my-component-header></my-component-header>
    <my-component-footer></my-component-footer>
</my-component>
```

Para definir un slot por defecto solo debes declarar en las props la prop slot, ejemplo:

```javascript
myComponentHeader.props = {
    slot: { type:String, value: "header"}
}

myComponentFooter.props = {
    slot: { type:String, value: "footer"}
}
```

Considere esto practico solo si la composición esta apalancada al contenedor, esto no evita que ud modifique la propiedad slot desde la instancia del componente

### Slot condicional.

Atomico ofrece un hook dentro del package [**@atomico/hooks/use-slot**](https://github.com/atomicojs/docs/blob/es/guias/sistemas-de-diseno/broken-reference/README.md)\*\* \*\*que anexa el evento [**slotchange**](https://developer.mozilla.org/en-US/docs/Web/API/HTMLSlotElement/slotchange_event) a una referencia, este le permitirá ocultar slots si estos no declaran contenido, ejemplo:

```jsx
import { useRef } from "atomico";
import { useSlot } from "@atomico/hooks/use-slot";

function component(){
    const ref = useRef();
    const childNodes = useSlot(ref);
    return <host shadowDom>
        <header style={{
            display: childNodes.length? "block": "none"
        }}>
            <slot name="header" ref={ref}/>
        </header>
    </host>
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://atomico.gitbook.io/doc/espanol/guias/sistemas-de-diseno/slots.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
