-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enhance create-ui5-element command to create component in TS (#…
…6609) * feat: enhance create-ui5-element command to create component in Typescript * feat: add second argument as an option to create-ui5-element command for specifying the language * feat: add third argument as an option for specifying a custom tag
- Loading branch information
Showing
3 changed files
with
266 additions
and
108 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
77 changes: 77 additions & 0 deletions
77
packages/tools/lib/create-new-component/jsFileContentTemplate.js
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,77 @@ | ||
const jsFileContentTemplate = (componentName, tagName, library, packageName) => { | ||
return `import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js"; | ||
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js"; | ||
import ${componentName}Template from "./generated/templates/${componentName}Template.lit.js"; | ||
// Styles | ||
import ${componentName}Css from "./generated/themes/${componentName}.css.js"; | ||
/** | ||
* @public | ||
*/ | ||
const metadata = { | ||
tag: "${tagName}", | ||
properties: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ { | ||
// | ||
}, | ||
slots: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ { | ||
// | ||
}, | ||
events: /** @lends sap.ui.webc.${library}.${componentName}.prototype */ { | ||
// | ||
}, | ||
}; | ||
/** | ||
* @class | ||
* | ||
* <h3 class="comment-api-title">Overview</h3> | ||
* | ||
* | ||
* <h3>Usage</h3> | ||
* | ||
* For the <code>${tagName}</code> | ||
* <h3>ES6 Module Import</h3> | ||
* | ||
* <code>import ${packageName}/dist/${componentName}.js";</code> | ||
* | ||
* @constructor | ||
* @author SAP SE | ||
* @alias sap.ui.webc.${library}.${componentName} | ||
* @extends sap.ui.webc.base.UI5Element | ||
* @tagname ${tagName} | ||
* @public | ||
*/ | ||
class ${componentName} extends UI5Element { | ||
static get metadata() { | ||
return metadata; | ||
} | ||
static get render() { | ||
return litRender; | ||
} | ||
static get styles() { | ||
return ${componentName}Css; | ||
} | ||
static get template() { | ||
return ${componentName}Template; | ||
} | ||
static get dependencies() { | ||
return []; | ||
} | ||
static async onDefine() { | ||
} | ||
} | ||
${componentName}.define(); | ||
export default ${componentName}; | ||
`; | ||
}; | ||
|
||
module.exports = jsFileContentTemplate; |
84 changes: 84 additions & 0 deletions
84
packages/tools/lib/create-new-component/tsFileContentTemplate.js
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,84 @@ | ||
const tsFileContentTemplate = (componentName, tagName, library, packageName) => { | ||
return `import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js"; | ||
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js"; | ||
import property from "@ui5/webcomponents-base/dist/decorators/property.js"; | ||
import slot from "@ui5/webcomponents-base/dist/decorators/slot.js"; | ||
import event from "@ui5/webcomponents-base/dist/decorators/event.js"; | ||
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js"; | ||
import ${componentName}Template from "./generated/templates/${componentName}Template.lit.js"; | ||
// Styles | ||
import ${componentName}Css from "./generated/themes/${componentName}.css.js"; | ||
/** | ||
* @class | ||
* | ||
* <h3 class="comment-api-title">Overview</h3> | ||
* | ||
* | ||
* <h3>Usage</h3> | ||
* | ||
* For the <code>${tagName}</code> | ||
* <h3>ES6 Module Import</h3> | ||
* | ||
* <code>import ${packageName}/dist/${componentName}.js";</code> | ||
* | ||
* @constructor | ||
* @author SAP SE | ||
* @alias sap.ui.webc.${library}.${componentName} | ||
* @extends sap.ui.webc.base.UI5Element | ||
* @tagname ${tagName} | ||
* @public | ||
*/ | ||
@customElement({ | ||
tag: "${tagName}", | ||
renderer: litRender, | ||
styles: ${componentName}Css, | ||
template: ${componentName}Template, | ||
dependencies: [], | ||
}) | ||
/** | ||
* Example custom event. | ||
* Please keep in mind that all public events should be documented in the API Reference as shown below. | ||
* | ||
* @event sap.ui.webc.${library}.${componentName}#interact | ||
* @public | ||
*/ | ||
@event("interact", { detail: { /* event payload ( optional ) */ } }) | ||
class ${componentName} extends UI5Element { | ||
/** | ||
* Defines the value of the component. | ||
* | ||
* @type {string} | ||
* @name sap.ui.webc.${library}.${componentName}.prototype.value | ||
* @defaultvalue "" | ||
* @public | ||
*/ | ||
@property() | ||
value!: string; | ||
/** | ||
* Defines the text of the component. | ||
* | ||
* @type {Node[]} | ||
* @name sap.ui.webc.${library}.${componentName}.prototype.default | ||
* @slot | ||
* @public | ||
*/ | ||
@slot({ type: Node, "default": true }) | ||
text!: Array<Node>; | ||
static async onDefine() { | ||
} | ||
} | ||
${componentName}.define(); | ||
export default ${componentName}; | ||
`; | ||
}; | ||
|
||
module.exports = tsFileContentTemplate; |