-
Notifications
You must be signed in to change notification settings - Fork 13
chore: repo card with story and test #737
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
solidjs-tailwind/src/components/PrivacyBadge/PrivacyBadge.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { splitProps } from 'solid-js'; | ||
|
|
||
| const PrivacyBadge = (props) => { | ||
| const [local] = splitProps(props, ['visibility']); | ||
| return ( | ||
| <span class="py-0.5 px-2 text-xs rounded-xl text-gray-600 border border-gray-300 font-medium capitalize"> | ||
| {local.visibility} | ||
| </span> | ||
| ); | ||
| }; | ||
|
|
||
| export default PrivacyBadge; |
15 changes: 15 additions & 0 deletions
15
solidjs-tailwind/src/components/PrivacyBadge/PrivacyBadge.stories.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import PrivacyBadge from './PrivacyBadge'; | ||
|
|
||
| export default { | ||
| title: 'Components/PrivacyBadge', | ||
| argTypes: { | ||
| visibility: {}, | ||
| }, | ||
| }; | ||
|
|
||
| const Template = (args) => <PrivacyBadge {...args} />; | ||
|
|
||
| export const Default = Template.bind({}); | ||
| Default.args = { | ||
| visibility: 'Public', | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default as PrivacyBadge } from './PrivacyBadge'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { Link } from '@solidjs/router'; | ||
| import { Show, splitProps } from 'solid-js'; | ||
| import RepoMeta from '../RepoMeta/RepoMeta'; | ||
| import { OcStar2 } from 'solid-icons/oc'; | ||
| import PrivacyBadge from '../PrivacyBadge/PrivacyBadge'; | ||
|
|
||
| const RepoCard = (props) => { | ||
| const [local] = splitProps(props, [ | ||
| 'name', | ||
| 'description', | ||
| 'primaryLanguage', | ||
| 'stargazerCount', | ||
| 'owner', | ||
| 'isProfilePage', | ||
| 'updatedAt', | ||
| 'visibility', | ||
| ]); | ||
| const repoNameWithOwnerLink = () => | ||
| `${local.owner?.login || ''}/${local.name || ''}`; | ||
| const repoNameWithOwner = () => | ||
| `${!local.isProfilePage ? `${local.owner?.login || ''}/` : ''}${ | ||
| local.name || '' | ||
| }`; | ||
|
|
||
| return ( | ||
| <div class="px-4 py-8 border-b border-gray-200 first-of-type:border-t flex justify-between flex-wrap md:flex-nowrap gap-x-4"> | ||
| <div class="col-span-12 md:col-span-7 text-left"> | ||
| <h3 class="mb-4"> | ||
| <Link href={repoNameWithOwnerLink()}> | ||
| <span class="text-xl text-blue-600 font-semibold hover:underline mr-3"> | ||
| {repoNameWithOwner()} | ||
| </span> | ||
| </Link> | ||
| <PrivacyBadge visibility={local.visibility} /> | ||
| </h3> | ||
| <Show when={local.description}> | ||
| <div class="text-gray-600 text-sm max-w-prose"> | ||
| {local.description} | ||
| </div> | ||
| </Show> | ||
| <RepoMeta | ||
| primaryLanguage={local.primaryLanguage} | ||
| stargazerCount={local.stargazerCount} | ||
| updatedAt={local.updatedAt} | ||
| /> | ||
| </div> | ||
| <div class="col-span-12 md:col-span-5 flex items-start md:justify-end mt-4 lg:mt-0"> | ||
| <button class="inline-flex gap-2 items-center px-3 py-1 rounded-md bg-gray-100 bg-opacity-75 border border-gray-300 text-sm font-medium text-gray-800 hover:bg-gray-200 hover:bg-opacity-50"> | ||
| <span class="-translate-x-1 -translate-y-[0.45rem]"> | ||
| <OcStar2 size={2} /> | ||
| </span> | ||
| <span class="ml-2">Star</span> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
| export default RepoCard; |
51 changes: 51 additions & 0 deletions
51
solidjs-tailwind/src/components/RepoCard/RepoCard.spec.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { Router } from '@solidjs/router'; | ||
| import { render } from 'solid-testing-library'; | ||
| import { beforeEach, describe, expect, it } from 'vitest'; | ||
| import RepoCard from './RepoCard'; | ||
| import { repoCardProps } from './data'; | ||
|
|
||
| describe('RepoCard for profilepage', () => { | ||
| let wrapper; | ||
| beforeEach(async () => { | ||
| wrapper = await render(() => ( | ||
| <Router> | ||
| <RepoCard {...repoCardProps} /> | ||
| </Router> | ||
| )); | ||
| }); | ||
|
|
||
| it('should mount', () => { | ||
| expect(wrapper).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('a tag text should contain only name', async () => { | ||
| const repoName = await wrapper.getByText(repoCardProps.name); | ||
| expect(repoName).toBeVisible(); | ||
| }); | ||
| }); | ||
| describe('RepoCard for non profile page', () => { | ||
| let wrapper; | ||
| const notProfileData = { | ||
| ...repoCardProps, | ||
| isProfilePage: false, | ||
| }; | ||
|
|
||
| beforeEach(async () => { | ||
| wrapper = await render(() => ( | ||
| <Router> | ||
| <RepoCard {...notProfileData} /> | ||
| </Router> | ||
| )); | ||
| }); | ||
|
|
||
| it('should mount', () => { | ||
| expect(wrapper).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('a tag text should contain owner/name', async () => { | ||
| const repowithOwner = await wrapper.getByText( | ||
| `${notProfileData.owner.login}/${notProfileData.name}` | ||
| ); | ||
| expect(repowithOwner).toBeVisible(); | ||
| }); | ||
| }); |
28 changes: 28 additions & 0 deletions
28
solidjs-tailwind/src/components/RepoCard/RepoCard.stories.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { Router } from '@solidjs/router'; | ||
| import RepoCard from './RepoCard'; | ||
| import { repoCardProps } from './data'; | ||
|
|
||
| export default { | ||
| title: 'Components/Repo Card', | ||
| component: RepoCard, | ||
| argTypes: { | ||
| name: {}, | ||
| description: {}, | ||
| primaryLanguage: {}, | ||
| owner: {}, | ||
| isProfilePage: {}, | ||
| stargazerCount: {}, | ||
| }, | ||
| }; | ||
|
|
||
| const Template = (args) => ( | ||
| <Router> | ||
| <RepoCard {...args} /> | ||
| </Router> | ||
| ); | ||
|
|
||
| export const Default = Template.bind({}); | ||
|
|
||
| Default.args = { | ||
vyktoremario marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ...repoCardProps, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| export const repoCardProps = { | ||
| name: 'cowrywise-unsplashed', | ||
| owner: { | ||
| login: 'hdjerry', | ||
| }, | ||
| isProfilePage: true, | ||
| stargazerCount: 2, | ||
| visibility: 'Private', | ||
| primaryLanguage: { | ||
| color: 'yellow', | ||
| name: 'Javascript', | ||
| }, | ||
| description: | ||
| 'Using basic pull requests to add your name and github link to BE A MEMBER of ZTM-ng', | ||
| updatedAt: '23 Sep 2020', | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default as RepoCard } from './RepoCard'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { Show, splitProps } from 'solid-js'; | ||
| import { OcStar2 } from 'solid-icons/oc'; | ||
| import getFriendlyDate from '../../helper/getFriendlyDate'; | ||
|
|
||
| const RepoMeta = (props) => { | ||
| const [local] = splitProps(props, [ | ||
| 'primaryLanguage', | ||
| 'stargazerCount', | ||
| 'updatedAt', | ||
| ]); | ||
|
|
||
| const friendlyUpdatedAt = () => getFriendlyDate(local.updatedAt); | ||
|
|
||
| return ( | ||
| <div class="flex mt-4 text-xs text-gray-600 space-x-4"> | ||
| <Show when={local.primaryLanguage}> | ||
| <div class="language flex items-center gap-3"> | ||
| <span | ||
| style={{ | ||
| 'background-color': local.primaryLanguage.color || '#ccc', | ||
| }} | ||
| class="w-3 h-3 rounded-full" | ||
| /> | ||
| <span>{local.primaryLanguage.name}</span> | ||
| </div> | ||
| </Show> | ||
| <Show when={local.stargazerCount}> | ||
| <div class="language flex items-baseline gap-3"> | ||
| <span class="-translate-x-1 -translate-y-[0.65rem]"> | ||
| <OcStar2 size={2} /> | ||
| </span> | ||
| <span>{local.stargazerCount}</span> | ||
| </div> | ||
| </Show> | ||
| <span class="text-subtitle">Updated {friendlyUpdatedAt()}</span> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default RepoMeta; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default as RepoMeta } from './RepoMeta'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import dayjs from 'dayjs'; | ||
| import relativeTime from 'dayjs/plugin/relativeTime'; | ||
|
|
||
| const getFriendlyDate = (dateStr) => { | ||
| dayjs.extend(relativeTime); | ||
|
|
||
| const formatted = dayjs(dateStr).fromNow(); | ||
|
|
||
| return formatted; | ||
| }; | ||
|
|
||
| export default getFriendlyDate; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.