24.1.1 • Published 9 months ago

@servicenow/ui-core v24.1.1

Weekly downloads
79
License
MIT
Repository
-
Last release
9 months ago

@servicenow/ui-core

createCustomElement

Define a custom element.

ParamTypeDescription
elementNamestringThe tag name of the custom element.
configObjectThe custom element configuration.
config.initialStateObjectThe initial state for a component.
config.propertiesObjectThe properties used by a custom element.
config.properties.nameObjectThe name of the property.
config.properties.name.default*The default value of the property.
config.properties.name.computedfunctionA function that computes the property value.
config.properties.name.computed.stateObjectThe custom element state.
config.properties.name.onChangefunctionA function that will be called with the new property value, the previous value, and the dispatch function.
config.properties.name.reflectbooleanReflect property change to corresponding attribute.
config.properties.name.unstableParsebooleanParse attribute values when corresponding properties are set.
config.properties.name.readOnlybooleanProperty cannot be externally set.
config.actionsObjectThe actions the custom element dispatches.
config.actions.typeObjectThe action type, name.
config.actions.privatebooleanIndicates if the action is visible outside of the custom element.
config.actions.handlersArrayEffect handlers to run when the action type is dispatched.
config.rendererObjectThe renderer to be used by the custom element.
config.renderer.typefunctionThe library that renders the view.
config.renderer.viewfunctionA function that is executed by onStateChange.
config.renderer.transformStatefunctionA function that executes before a component's state is passed to the handler.
config.onDisconnectfunctionA function that executes when the custom element is disconnected.
config.onConnectfunctionA function that executes when the custom element is connected.
config.behaviorsArrayBehaviors to applied to the custom element.

Example

import {createCustomElement} from '@servicenow/ui-core';
import snabbdom from '@servicenow/ui-renderer-snabbdom';

createCustomElement('sn-hello-world', {
  properties: {
    name: {
      default: 'Fred'
    }
  },
  renderer: {
    type: snabbdom,
    transformState({properties}) { return properties; },
    view: ({name}) => { return <p>Hello {name}!</p>; }
  }
});

Action Routing

Actions will "bubble" up the component hierarchy unless they are explictly stopped by dispatch meta data, {stopPropagtion: true}, or part of the stopPropagtion configuration for a component definition.

dispatch('SOMETHING_HAPPENED', {somethingHappened: true}, {stopPropagtion: true});

OR

createCustomElement('sn-foo', () => null, {
  stopPropagtion: ['SOMETHING_HAPPENED']
});
@storeworkflows/swf-date-time-picker@storeworkflows/swf-dropdown@everything-registry/sub-chunk-825@infinitebrahmanuniverse/nolb-_servnpm-ui-component-test@nowcomponents/fa-icon@nowcomponents/tag-fieldtest-simple-button2@saleswon/fa-icon@saleswon/sw-avatar@saleswon/sw-editor@saleswon/sw-loader@saleswon/tag-field@servicenow/behavior-defer@servicenow/behavior-dragdrop@servicenow/behavior-fit@servicenow/behavior-focus@servicenow/behavior-key-binding@servicenow/behavior-media-query@servicenow/behavior-modal@servicenow/behavior-resizable@servicenow/behavior-resize@servicenow/behavior-rtl@servicenow/behavior-truncation@servicenow/now-popover@servicenow/now-progress-bar@servicenow/now-radio-buttons@servicenow/now-rich-text@servicenow/now-select@servicenow/now-split-button@servicenow/now-stepper@servicenow/now-tabs@servicenow/now-template-card@servicenow/now-template-message@servicenow/now-text-link@servicenow/now-textarea@servicenow/now-toggle@servicenow/now-tooltip@servicenow/now-typeahead@servicenow/sdk-ci@servicenow/library-enhanced-element@servicenow/library-enhanced-test@servicenow/now-accordion@servicenow/now-alert@servicenow/now-avatar@servicenow/now-badge@servicenow/now-breadcrumbs@servicenow/now-button@servicenow/now-card@servicenow/now-checkbox@servicenow/now-collapse@servicenow/now-content-tree@servicenow/now-dropdown@servicenow/now-heading@servicenow/now-highlighted-value@servicenow/now-icon@servicenow/now-iframe@servicenow/now-illustration@servicenow/now-image@servicenow/now-input@servicenow/now-label-value@servicenow/now-legacy-icon@servicenow/now-loader@servicenow/now-message@servicenow/now-modal@servicenow/now-pagination-control@servicenow/now-pill@tenonhq/hello-world-npm
24.1.1

9 months ago

19.4.2

3 years ago

18.2.5

4 years ago

17.0.1

4 years ago

17.0.0-rc.17

4 years ago

17.0.0-rc.15

4 years ago