File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import Component from '@glimmer/component' ;
2+ import { tracked } from '@glimmer/tracking' ;
3+ import { action } from '@ember/object' ;
4+
5+ export default class CopyButtonComponent extends Component {
6+ @tracked isCopied = false ;
7+ @tracked copyError = false ;
8+
9+ @action
10+ async copyText ( ) {
11+ try {
12+ await navigator . clipboard . writeText ( this . args . textToCopy ) ;
13+ this . isCopied = true ;
14+ this . copyError = false ;
15+
16+ setTimeout ( ( ) => {
17+ this . isCopied = false ;
18+ } , 2000 ) ;
19+ } catch ( err ) {
20+ console . error ( 'Failed to copy text:' , err ) ;
21+ this . copyError = true ;
22+
23+ setTimeout ( ( ) => {
24+ this . copyError = false ;
25+ } , 2000 ) ;
26+ }
27+ }
28+
29+ get buttonLabel ( ) {
30+ if ( this . isCopied ) {
31+ return 'ROR ID copied to clipboard' ;
32+ }
33+ if ( this . copyError ) {
34+ return 'Failed to copy ROR ID' ;
35+ }
36+ return 'Copy ROR ID to clipboard' ;
37+ }
38+
39+ get buttonTitle ( ) {
40+ if ( this . isCopied ) {
41+ return 'Copied!' ;
42+ }
43+ if ( this . copyError ) {
44+ return 'Copy failed' ;
45+ }
46+ return 'Copy ROR ID' ;
47+ }
48+
49+ get iconClass ( ) {
50+ if ( this . isCopied ) {
51+ return 'fa-solid fa-check' ;
52+ }
53+ if ( this . copyError ) {
54+ return 'fa-solid fa-exclamation-triangle' ;
55+ }
56+ return 'fa-solid fa-copy' ;
57+ }
58+ }
Original file line number Diff line number Diff line change 11@import ' ember-power-select' ;
22@import " components/organizations/api-client-registration-form" ;
3+ @import " components/copy-button" ;
34
45$green : #53baa1 ;
56$dark-grey : #505759 ;
Original file line number Diff line number Diff line change 1+ .copy-button {
2+ display : inline-block ;
3+ margin-left : 0.5rem ;
4+ margin-bottom : 0.25rem ;
5+ padding : 0 ;
6+ background-color : transparent ;
7+ border : none ;
8+ color : #293030 ;
9+ font-size : 1.25rem ;
10+ line-height : 1 ;
11+ cursor : pointer ;
12+ transition : color 0.2s ease , opacity 0.2s ease ;
13+ vertical-align : middle ;
14+ opacity : 0.7 ;
15+
16+ & :hover {
17+ color : #53baa1 ;
18+ opacity : 1 ;
19+ }
20+
21+ & :focus {
22+ outline : none ;
23+ }
24+
25+ & :focus-visible {
26+ outline : 2px solid #53baa1 ;
27+ outline-offset : 2px ;
28+ border-radius : 2px ;
29+ opacity : 1 ;
30+ }
31+
32+ & :active {
33+ transform : scale (0.95 );
34+ }
35+
36+ & .copy-button--success {
37+ opacity : 1 ;
38+ }
39+
40+ & .copy-button--error {
41+ color : #da3200 ;
42+ opacity : 1 ;
43+ }
44+
45+ i {
46+ pointer-events : none ;
47+ }
48+
49+ @media screen and (max-width : 420px ) {
50+ font-size : 1rem ;
51+ margin-left : 0.35rem ;
52+ }
53+ }
54+
55+ .sr-only {
56+ position : absolute ;
57+ width : 1px ;
58+ height : 1px ;
59+ padding : 0 ;
60+ margin : -1px ;
61+ overflow : hidden ;
62+ clip : rect (0 , 0 , 0 , 0 );
63+ white-space : nowrap ;
64+ border : 0 ;
65+ }
Original file line number Diff line number Diff line change 1+ <button
2+ type =" button"
3+ class =" copy-button {{ if this.isCopied ' copy-button--success' }} {{ if this.copyError ' copy-button--error' }} "
4+ aria-label ={{ this.buttonLabel }}
5+ title =" Copy ROR ID"
6+ {{ on " click" this.copyText }}
7+ >
8+ <i class ={{ this.iconClass }} aria-hidden =" true" ></i >
9+ </button >
10+ <span class =" sr-only" role =" status" aria-live =" polite" aria-atomic =" true" >
11+ {{ #if this.isCopied }}
12+ ROR ID copied to clipboard
13+ {{ /if }}
14+ </span >
Original file line number Diff line number Diff line change 77 <div class =" col-lg-9 col-sm-12" >
88 <h1 >
99 <img class =" ror-id mb-1" src =" /assets/ror-logo-small.png" alt =" ROR ID" > <LinkTo @route =" organizations.show" @model ={{ this.model.id }} class =" card-link logo-link" >https://ror.org/{{ this.model.id }} </LinkTo >
10+ <CopyButton @textToCopy =" https://ror.org/{{ this.model.id }} " />
1011 </h1 >
1112 </div >
1213 <div class =" col-lg-3 col-sm-12" >
You can’t perform that action at this time.
0 commit comments