-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UseParent atom and Comment component; update README
- Loading branch information
tech_e
committed
Dec 5, 2024
1 parent
0070b49
commit 2e9f62d
Showing
5 changed files
with
102 additions
and
4 deletions.
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
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
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,11 @@ | ||
/** | ||
* This will create a comment. | ||
* | ||
* @param {object} props | ||
* @returns {object} | ||
*/ | ||
export const Comment = (props) => ({ | ||
tag: 'comment', | ||
textContent: `${props.type} placeholder`, | ||
onCreated: props.onCreated | ||
}); |
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
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,72 @@ | ||
import { Builder } from "@base-framework/base"; | ||
import { Comment as BaseComment } from "src/comment.js"; | ||
|
||
/** | ||
* This will set up the update layout function. | ||
* | ||
* @param {function} callBack | ||
* @param {object} ele | ||
* @param {object} parent | ||
* @returns {function} | ||
*/ | ||
const updateLayout = (callBack, ele, parent) => | ||
{ | ||
const layout = callBack(parent); | ||
if (typeof layout === "undefined") | ||
{ | ||
return; | ||
} | ||
|
||
/** | ||
* This will build the layout and insert it after the | ||
* comment element. | ||
*/ | ||
const frag = Builder.build(layout, null, parent); | ||
ele.parentNode.insertBefore(frag, ele.nextSibling); | ||
}; | ||
|
||
/** | ||
* This will create a comment. | ||
* | ||
* @param {object} props | ||
* @returns {object} | ||
*/ | ||
const Comment = (props) => BaseComment({ | ||
type: 'use', | ||
onCreated: props.onCreated | ||
}); | ||
|
||
/** | ||
* This will create a use parent tag. | ||
* | ||
* @overload | ||
* @param {object} data | ||
* @param {string} prop | ||
* @param {function} callBack | ||
* | ||
* @overload | ||
* @param {string} prop | ||
* @param {function} callBack | ||
* | ||
* @returns {object} | ||
*/ | ||
export const UseParent = (...args) => | ||
{ | ||
const settings = [...args]; | ||
const callBack = settings.pop(); | ||
if (typeof callBack !== 'function') | ||
{ | ||
return; | ||
} | ||
|
||
/** | ||
* This will create a comment to use as a placeholder | ||
* to keep the layout in place. | ||
*/ | ||
return Comment({ | ||
onCreated: (ele, parent) => | ||
{ | ||
updateLayout(callBack, ele, parent); | ||
} | ||
}); | ||
}; |