Skip to content

Commit

Permalink
feat(links): consume new caas-mapper structure of Links in `RichTextE…
Browse files Browse the repository at this point in the history
…lement`s (#78)

* feat(links): consume new caas-mapper structure of `Link`s in `RichTextElement`s
* feat(package.json & package-lock.json): update fsxa-stack dependencies

Increase fsxa-nuxt-module version to 7.0.0, fsxa-api version to 10.0.0 and fsxa-pattern-library to
8.0.0
  • Loading branch information
sechw authored May 17, 2022
1 parent 2520d08 commit 3c442f4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 45 deletions.
72 changes: 45 additions & 27 deletions components/fsxa/richtext/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,58 @@
import type { Link as RichTextLink, Reference, CaaSApi_Option } from 'fsxa-api'
import { FSXABaseRichTextElement } from 'fsxa-pattern-library'
import { Component } from 'vue-property-decorator'

export type Data = {
type: 'internal_link'
export interface InternalLink extends RichTextLink {
template: 'internal_link'
data: {
lt_link: {
value: {
identifier: string
}
}
lt_link: Reference
lt_text: string
}
}

export interface ExternalLink extends RichTextLink {
template: 'external_link'
data: {
lt_url: string
lt_text: string
lt_link_behavior: CaaSApi_Option
}
}

@Component({
name: 'RichTextLink'
})
class Link extends FSXABaseRichTextElement<Data> {
class Link extends FSXABaseRichTextElement<InternalLink | ExternalLink> {
render() {
return (
<a
class="underline"
href={
this.data.type === 'internal_link'
? this.getUrlByPageId(this.data.data.lt_link.value.identifier) ||
'#'
: '#'
}
onClick={(event) => {
event.preventDefault()
this.triggerRouteChange({
pageId: this.data.data.lt_link.value.identifier
})
}}
>
{this.renderContent()}
</a>
)
switch (this.data.template) {
case 'internal_link':
return (
<a
class="underline"
href={
this.getUrlByPageId(this.data.data.lt_link.referenceId) || '#'
}
onClick={(event) => {
event.preventDefault()
this.triggerRouteChange({
pageId: (this.data as InternalLink).data.lt_link.referenceId
})
}}
>
{this.renderContent()}
</a>
)
case 'external_link':
return (
<a
class="underline"
href={this.data.data.lt_url || '#'}
target={this.data.data.lt_link_behavior.identifier}
>
{this.renderContent()}
</a>
)
}
}
}
export default Link
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ To use this base component a new class has to be created which extends the `FSXA
class Component extends FSXABaseRichTextElement {}
----

If you want to have type support for your data you can provide an interface and pass it as an generic like here the `Data` interface.
If you want to have type support for your data you can provide an interface and pass it as an generic like here the `Data` interface or extend the `Link` interface in case of Links.

[source,javascript]
----
Expand All @@ -34,7 +34,7 @@ class Component extends FSXABaseRichTextElement<Data> {}

=== `data` - Object

Returns all available data attributes, for example the `data-fs-style` to determinate the styling.
Returns all available data attributes, for example the `data-fs-style` to determinate the styling, respectively this is a `Link` and contains nested data that is maintained in FirstSpirit.

=== `content` - Array

Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"dependencies": {
"@nuxt/core": "^2.15.8",
"@nuxtjs/axios": "^5.13.6",
"fsxa-nuxt-module": "^6.0.1",
"fsxa-nuxt-module": "^7.0.0",
"nuxt-start": "^2.15.8"
},
"devDependencies": {
Expand Down Expand Up @@ -69,8 +69,8 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-nuxt": ">=2.0.0",
"eslint-plugin-prettier": "^4.0.0",
"fsxa-api": "^9.0.2",
"fsxa-pattern-library": "^7.0.2",
"fsxa-api": "^10.0.0",
"fsxa-pattern-library": "^8.0.0",
"fsxa-ui": "^4.1.0",
"husky": "^4.0.0",
"jest": "^24.1.0",
Expand Down

0 comments on commit 3c442f4

Please sign in to comment.