-
Notifications
You must be signed in to change notification settings - Fork 27
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
Controller: @phase2/outline-controller-slot-manager
#389
Open
bardleb
wants to merge
9
commits into
next
Choose a base branch
from
feature/slot-controller-package
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+216
−0
Open
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ada4465
feat: Separating slot controller out into a package
371ed8b
fix: updated readme
2c0f57d
fix: update README
shaal 8573d7a
Merge branch 'next' into feature/slot-controller-package
himerus 61f0f24
fix(prettier): Fixing improper indentations.
himerus ff89682
Merge branch 'next' into feature/slot-controller-package
glitchgirl a208ab9
feat(slot-manager): Simplified logic dramatically.
himerus 6fc96ff
feat(slot-manager): Fixed version number.
himerus cd94916
feat(slot-manager): Tweaked docs.
himerus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Slot Manager | ||
|
||
The `SlotManager` is a reactive controller that allows cloning slots into the shadow DOM of a component. It provides methods for managing slots, adding annotations, and dispatching events from cloned slots in the shadow DOM to the equivalent slots in the light DOM. | ||
|
||
## Installation | ||
|
||
To use the `SlotManager`, you need to install the required dependencies: | ||
|
||
```bash | ||
yarn add -D @phase2/slot-manager | ||
``` | ||
|
||
## Usage | ||
|
||
Import the `SlotManager` and instantiate it in your component: | ||
|
||
```javascript | ||
import { SlotManager } from './slot-manager'; | ||
|
||
class MyComponent extends LitElement { | ||
constructor() { | ||
super(); | ||
const SlotManager = new SlotManager(this); | ||
// ... @todo Add more usage examples | ||
// default slot example | ||
// slot exist function | ||
// renderInShadow example | ||
// conditionalSlot example | ||
} | ||
} | ||
``` | ||
himerus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## API | ||
|
||
### SlotManager(host: ReactiveControllerHost & HTMLElement) | ||
|
||
Creates a new instance of the `SlotManager` for the given host element. | ||
|
||
- `host`: The host element that will be controlled by the `SlotManager`. | ||
|
||
#### Methods | ||
|
||
##### getSlottedNodes(slotName?: string | null): Array<Node> | ||
|
||
Returns an array of slotted nodes for the specified slot name. | ||
|
||
- `slotName`: The name of the slot. If not provided, returns the default slot nodes. | ||
|
||
##### exist(slotName?: string | null): boolean | ||
|
||
Checks if a slot exists. | ||
|
||
- `slotName`: The name of the slot. If not provided, checks for the default slot. | ||
|
||
##### addAnnotations(slotName: string, lightDomSlot: ChildNode): HTMLElement | ||
|
||
Adds annotations to a slot, such as cloned-slot attributes and comments in the light DOM. | ||
|
||
- `slotName`: The name of the slot. | ||
- `lightDomSlot`: The light DOM slot to annotate. | ||
|
||
##### dispatchEventsToLightDom(eventsToDispatch: string[], clonedSlot: HTMLElement): void | ||
|
||
Dispatches events from cloned slots in the shadow DOM to the equivalent slots in the light DOM. | ||
|
||
- `eventsToDispatch`: An array of event types to dispatch. | ||
- `clonedSlot`: The cloned slot in the shadow DOM. | ||
|
||
##### renderInShadow(slotName?: string, wrapperElement?: string | null, eventsToDispatch?: string[], addAnnotations?: boolean): Array<HTMLElement> | null | ||
|
||
Renders the specified slot in the shadow DOM. | ||
|
||
- `slotName`: The name of the slot. If not provided, renders the default slot. | ||
- `wrapperElement`: Optional wrapper element for each slot. | ||
- `eventsToDispatch`: An array of event types to dispatch from the cloned slots. | ||
- `addAnnotations`: Whether to add annotations to the slot. Defaults to `true`. | ||
|
||
##### conditionalSlot(slotName: string, renderInShadow?: boolean, extraClasses?: string | null, extraAttributes?: { name: string, value: string }[]): TemplateResult | null | ||
|
||
Conditionally renders a slot with a wrapper and additional classes. | ||
|
||
- `slotName`: The name of the slot. | ||
- `renderInShadow`: Whether to render the slot in the shadow DOM. Defaults to `true`. | ||
- `extraClasses`: Additional classes to add to the wrapper element. Defaults to `null`. | ||
- `extraAttributes`: Additional attributes to add to the wrapper element. Defaults to an empty array. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { SlotManager } from './src/slot-manager'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "@phase2/outline-controller-slot-manager", | ||
"version": "0.0.1", | ||
"description": "Controller to help with slots (renderInShadow, exist, etc.)", | ||
"keywords": [ | ||
"outline components", | ||
"outline design", | ||
"slots", | ||
"shadow DOM" | ||
], | ||
"main": "index.ts", | ||
"types": "index.ts", | ||
"typings": "index.d.ts", | ||
"files": [ | ||
"/dist/", | ||
"/src/", | ||
"!/dist/tsconfig.build.tsbuildinfo" | ||
], | ||
"author": "Phase2 Technology", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/phase2/outline.git", | ||
"directory": "packages/controllers/slot-manager" | ||
}, | ||
"license": "BSD-3-Clause", | ||
"scripts": { | ||
"build": "node ../../../scripts/build.js", | ||
"package": "yarn publish" | ||
}, | ||
"dependencies": { | ||
"lit": "^2.3.1" | ||
}, | ||
"devDependencies": { | ||
"tslib": "^2.1.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"exports": { | ||
".": "./index.ts" | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add code examples for usage with ShadowDOM, LightDOM and how to handle a single unnamed (default) slot.