Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(githubStar): add tooltipText prop to GitHub Star component [KHCP-6183] #154

Merged
merged 6 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/core/misc-widgets/sandbox/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<main>
<div>
<h3>Awesome GitHub Star ⭐</h3>
<GithubStar :url="url" />
<GithubStar
:url="url"
/>
</div>
</main>
</div>
Expand Down
3 changes: 3 additions & 0 deletions packages/core/misc-widgets/sandbox/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { createApp } from 'vue'
import App from './App.vue'
import { GithubStar } from '../src'
import Kongponents from '@kong/kongponents'
import '@kong/kongponents/dist/style.css'

const app = createApp(App)
app.use(Kongponents)
app.component('GithubStar', GithubStar)
app.mount('#app')
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@ describe('<GithubStar />', () => {
cy.getTestId('github-star').find('a').should('be.visible')
cy.getTestId('github-star').find('.github-button').should('be.visible')
})

it('renders default tooltip text on mouseenter', () => {
cy.mount(GithubStar, {
props: {
url: 'http://github.com/kong/kong',
},
})
cy.get('.github-button').trigger('mouseenter')
cy.get('.k-popover').should('be.visible')
cy.get('.k-popover').contains('Star this repository on Github')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,43 @@
class="kong-ui-public-misc-widgets-github-star"
data-testid="github-star"
>
<a
aria-label="i18n.t('githubStar.ariaLabel')"
class="github-button"
data-color-scheme="no-preference: light; light: light; dark: light;"
data-show-count="true"
:href="url"
target="_blank"
>{{ i18n.t('githubStar.title') }}</a>
<KTooltip :label="tooltipLabel">
<span>
<a
:aria-label="i18n.t('githubStar.ariaLabel')"
class="github-button"
data-color-scheme="no-preference: light; light: light; dark: light;"
data-show-count="true"
:href="url"
target="_blank"
>
{{ i18n.t('githubStar.title') }}
</a>
</span>
</KTooltip>
</div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { computed, onMounted, ref } from 'vue'
import composables from '../../composables'
import { KTooltip } from '@kong/kongponents'

defineProps({
const { i18n } = composables.useI18n()

const props = defineProps({
url: {
type: String,
required: true,
},
tooltipText: {
type: String,
required: false,
default: '',
},
})

const { i18n } = composables.useI18n()
const tooltipLabel = computed((): string => props.tooltipText || i18n.t('githubStar.tooltipLabel'))

const scriptLoaded = ref<boolean>(false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ A Github Star component for displaying number of stars received by the repo on G
- required: `true`

Full URL to the GitHub repository.

#### `tooltipText`

- type: `String`
- required: `false`
- default: `Star this repository on Github`

String to display a tooltip when hovered.
3 changes: 2 additions & 1 deletion packages/core/misc-widgets/src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"githubStar": {
"title": "Star",
"ariaLabel": "Star buttons/github-buttons on GitHub"
"ariaLabel": "Star buttons/github-buttons on GitHub",
"tooltipLabel": "Star this repository on Github"
}
}