Skip to content

Commit 05d4cb6

Browse files
authored
add a href to website field (#2181)
* add a href to websitefield * make email field clickable
1 parent 21df636 commit 05d4cb6

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

packages/experiments-realm/email.gts

+9
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ export class EmailField extends StringField {
6969
<template>
7070
{{#if @model}}
7171
<EntityDisplayWithIcon @title={{@model}} @underline={{false}}>
72+
<:title>
73+
<a href='mailto:{{@model}}' rel='noopener noreferrer'>
74+
{{@model}}
75+
</a>
76+
</:title>
7277
<:icon>
7378
<MailIcon class='icon' />
7479
</:icon>
@@ -78,6 +83,10 @@ export class EmailField extends StringField {
7883
.icon {
7984
color: var(--boxel-400);
8085
}
86+
a:hover {
87+
text-decoration: underline;
88+
color: inherit;
89+
}
8190
</style>
8291
</template>
8392
};

packages/experiments-realm/website.gts

+44-2
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,59 @@ export class WebsiteField extends UrlField {
1818

1919
static atom = class Atom extends Component<typeof WebsiteField> {
2020
<template>
21-
<EntityDisplayWithIcon @title={{domainWithPath @model}}>
21+
<EntityDisplayWithIcon>
22+
<:title>
23+
{{! Display only domain and path, unlike URLField's full URL representation }}
24+
{{! Custom atom implementation for handling URL interactions }}
25+
{{#if @model}}
26+
{{#if (isValidUrl @model)}}
27+
<a href={{@model}} target='_blank' rel='noopener noreferrer'>
28+
{{domainWithPath @model}}
29+
</a>
30+
{{else}}
31+
Invalid URL
32+
{{/if}}
33+
{{/if}}
34+
</:title>
2235
<:icon>
2336
<WorldWwwIcon />
2437
</:icon>
2538
</EntityDisplayWithIcon>
39+
<style scoped>
40+
a:hover {
41+
text-decoration: underline;
42+
color: inherit;
43+
}
44+
</style>
2645
</template>
2746
};
2847

2948
static embedded = class Embedded extends Component<typeof WebsiteField> {
3049
<template>
31-
{{domainWithPath @model}}
50+
{{#if @model}}
51+
{{#if (isValidUrl @model)}}
52+
<a href={{@model}} target='_blank' rel='noopener noreferrer'>
53+
{{domainWithPath @model}}
54+
</a>
55+
{{else}}
56+
Invalid URL
57+
{{/if}}
58+
{{/if}}
59+
<style scoped>
60+
a:hover {
61+
text-decoration: underline;
62+
color: inherit;
63+
}
64+
</style>
3265
</template>
3366
};
3467
}
68+
69+
function isValidUrl(urlString: string): boolean {
70+
try {
71+
new URL(urlString);
72+
return true;
73+
} catch (err) {
74+
return false;
75+
}
76+
}

0 commit comments

Comments
 (0)