@@ -3,11 +3,14 @@ import { css } from '../../util/taggedString'
33import { baact , createRef } from '../../../baact/baact'
44import { theme } from '../../theme'
55import { NodeResult } from 'axe-core'
6- import { isHidden , ownText , removeAllChildren } from '../../util/dom'
6+ import { removeAllChildren } from '../../util/dom'
77import { baatSymbol } from '../../core/BAAT'
88import { BAATEvent , HighlightElement , SettingsChanged } from '../../types'
9- import { Icon } from '..'
10- import { settingNames } from "../../config" ;
9+ import { Icon } from '../Icon/Icon'
10+ import { settingNames } from "../../config" ;
11+ import { getElementFromNodeResult , getNameFromNodeResult } from '../../util/axe' ;
12+
13+ const padding = `${ theme . sizing . relative . tiny } ${ theme . sizing . relative . smaller } ` ;
1114
1215const styles = css `
1316 : host {
@@ -20,9 +23,10 @@ const styles = css`
2023 font- family: sans- serif;
2124 gap: ${ theme . sizing . relative . tiny } ;
2225 background- color : ${ theme . palette . white } ;
26+ color : ${ theme . palette . black } ;
2327 bor der: 1px solid;
2428 bor der- radius: 2px;
25- padding: ${ theme . sizing . relative . tiny } ${ theme . sizing . relative . smaller } ;
29+ padding: ${ padding } ;
2630 cursor : pointer;
2731 max- width: 100%;
2832 overflow: hidden;
@@ -35,22 +39,6 @@ const styles = css`
3539 butto n: hover {
3640 background- color : ${ theme . palette . grayLight } ;
3741 }
38-
39- butto n: disabled {
40- cursor : default;
41- color : # 333 ;
42- border : none;
43- padding-left : calc (6px + 12px + ${ theme . sizing . relative . smaller } );
44- }
45-
46- button : disabled : hover {
47- background-color : # fff ;
48- }
49-
50- # info {
51- padding-left : ${ theme . sizing . relative . huge } ;
52- font-size : ${ theme . semanticSizing . font . small } ;
53- }
5442`
5543
5644interface INodeLinkAccessor {
@@ -64,7 +52,6 @@ export class NodeResultLink extends BaseHTMLElement<INodeLinkAccessor> implement
6452 styles = styles
6553 static tagName : string = 'baat-node-link'
6654 private buttonRef = createRef < HTMLButtonElement > ( )
67- private infoRef = createRef < HTMLDivElement > ( )
6855 private element : HTMLElement | null = null ;
6956
7057 attributeChangedCallback < T extends keyof INodeLinkAccessor > ( name : T , oldValue : INodeLinkAccessor [ T ] , newValue : INodeLinkAccessor [ T ] ) {
@@ -80,33 +67,14 @@ export class NodeResultLink extends BaseHTMLElement<INodeLinkAccessor> implement
8067
8168 update ( ) {
8269 if ( ! this . shadowRoot || ! this . isConnected ) return
83- let name = ""
84- this . element = this . result ?. element ?? document . querySelector ( this ?. result ?. target ?. join ( ', ' ) ?? '' ) as HTMLElement | null
85- let hasLink = this . element && ! isHidden ( this . element )
86- const devMode = window [ baatSymbol ] . getSetting ( settingNames . developer )
70+ let name = getNameFromNodeResult ( this . result , window [ baatSymbol ] . getSetting ( settingNames . developer ) ) ;
71+ this . element = getElementFromNodeResult ( this . result ) ;
8772
8873 removeAllChildren ( this . buttonRef . value )
8974
90- if ( devMode ) {
91- name = this . result ?. target . join ( ', ' ) ?? this . element ?. tagName . toLowerCase ( ) ?? ''
92- } else {
93- name = this . element ? ownText ( this . element ) . trim ( ) : ""
94-
95- if ( name === "" ) name = this . element ?. tagName . toLowerCase ( ) ?? this . result ?. target . join ( ', ' ) ?? ""
96- }
75+ this . buttonRef . value . appendChild ( < Icon width = "16" height = "16" > < g fill = "none" stroke = "#000" stroke-linecap = "round" stroke-width = "4.65" > < circle cx = "24" cy = "24" r = "16.3" /> < path d = "m24 2.5v11" /> < path d = "m24 35v10.5" /> < path d = "m45.5 24h-10.5" /> < path d = "m13.5 24h-11" /> </ g > </ Icon > )
9776
98- if ( hasLink || devMode ) {
99- this . buttonRef . value . appendChild ( < Icon width = "16" height = "16" > < g fill = "none" stroke = "#000" stroke-linecap = "round" stroke-width = "4.65" > < circle cx = "24" cy = "24" r = "16.3" /> < path d = "m24 2.5v11" /> < path d = "m24 35v10.5" /> < path d = "m45.5 24h-10.5" /> < path d = "m13.5 24h-11" /> </ g > </ Icon > )
100- this . buttonRef . value . removeAttribute ( 'disabled' )
101- } else {
102- this . buttonRef . value . setAttribute ( 'disabled' , 'true' )
103- console . log ( this . buttonRef ) ;
104- }
10577 this . buttonRef . value . appendChild ( document . createTextNode ( name ) )
106-
107- this . infoRef . value . innerText = window [ baatSymbol ] . getSetting < boolean > ( settingNames . showAdditionalInformation )
108- ? this . result ?. failureSummary ?? ''
109- : ''
11078 }
11179
11280 initialize ( ) {
@@ -123,12 +91,11 @@ export class NodeResultLink extends BaseHTMLElement<INodeLinkAccessor> implement
12391 }
12492
12593 window [ baatSymbol ] . addEventListener ( BAATEvent . ChangeSettings , ( ( event : CustomEvent < SettingsChanged > ) => {
126- if ( event . detail . name === settingNames . developer || event . detail . name === settingNames . showAdditionalInformation ) this . update ( )
94+ if ( event . detail . name === settingNames . developer ) this . update ( )
12795 } ) as EventListener )
12896
12997 this . shadowRoot ?. appendChild ( < div >
13098 < button id = 'nodeLink' type = 'button' onClick = { handleClick } ref = { this . buttonRef } > </ button >
131- < div id = 'info' ref = { this . infoRef } > </ div >
13299 </ div > )
133100
134101 this . update ( )
0 commit comments