Skip to content

Commit

Permalink
✨ Add support for inputPosition option
Browse files Browse the repository at this point in the history
  • Loading branch information
laymonage committed Feb 3, 2022
1 parent 87158f6 commit 6f4e985
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 27 deletions.
3 changes: 3 additions & 0 deletions packages/@shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ type Giscus = {
theme?: Theme
reactionsEnabled?: BooleanString
emitMetadata?: BooleanString
inputPosition?: InputPosition
lang?: Lang
}

type BooleanString = '0' | '1'

type InputPosition = 'top' | 'bottom'

type Session = {
session: string
}
Expand Down
4 changes: 3 additions & 1 deletion packages/@shared/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function getIframeSrc({
theme = 'light',
reactionsEnabled = '1',
emitMetadata = '0',
inputPosition = 'bottom',
lang = 'en',
session,
origin
Expand All @@ -44,6 +45,7 @@ export function getIframeSrc({
theme,
reactionsEnabled,
emitMetadata,
inputPosition,
repo,
repoId,
category,
Expand Down Expand Up @@ -72,7 +74,7 @@ export function getIframeSrc({
params.term =
location.pathname.length < 2
? 'index'
: location.pathname.substr(1).replace(/\.\w+$/, '')
: location.pathname.substring(1).replace(/\.\w+$/, '')
break
}

Expand Down
1 change: 1 addition & 0 deletions packages/react/_debug/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ReactDOM.render(
term="Welcome to giscus-component Discussions"
reactionsEnabled="1"
emitMetadata="0"
inputPosition="bottom"
theme="light"
lang="en"
/>
Expand Down
28 changes: 2 additions & 26 deletions packages/react/lib/Giscus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,10 @@ function GiscusClient(props: GiscusProps) {
)
}

export default function Giscus({
repo,
repoId,
category,
categoryId,
mapping,
term,
theme,
reactionsEnabled,
emitMetadata,
lang
}: GiscusProps) {
export default function Giscus(props: GiscusProps) {
const [isMounted, setIsMounted] = useState(false)
useEffect(() => setIsMounted(true), [])

if (!isMounted) return null
return (
<GiscusClient
repo={repo}
repoId={repoId}
category={category}
categoryId={categoryId}
mapping={mapping}
term={term}
theme={theme}
reactionsEnabled={reactionsEnabled}
emitMetadata={emitMetadata}
lang={lang}
/>
)
return <GiscusClient {...props} />
}
1 change: 1 addition & 0 deletions packages/svelte/_debug/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
term="Welcome to giscus-component Discussions"
reactionsEnabled="1"
emitMetadata="0"
inputPosition="bottom"
theme="light"
lang="en"
/>
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte/lib/Giscus.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
export let theme: GiscusProps['theme'] = 'light'
export let reactionsEnabled: GiscusProps['reactionsEnabled'] = '1'
export let emitMetadata: GiscusProps['emitMetadata'] = '0'
export let inputPosition: GiscusProps['inputPosition'] = 'bottom'
let session = ''
$: src = getIframeSrc({
Expand All @@ -35,6 +36,7 @@
theme,
reactionsEnabled,
emitMetadata,
inputPosition,
session,
})
Expand Down
1 change: 1 addition & 0 deletions packages/vue/_debug/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
term="Welcome to giscus-component Discussions"
reactionsEnabled="1"
emitMetadata="0"
inputPosition="bottom"
theme="light"
lang="en"
/>
Expand Down
4 changes: 4 additions & 0 deletions packages/vue/lib/Giscus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const Giscus = defineComponent({
emitMetadata: {
type: String as PropType<GiscusProps['emitMetadata']>,
default: '0'
},
inputPosition: {
type: String as PropType<GiscusProps['inputPosition']>,
default: 'bottom'
}
},

Expand Down

0 comments on commit 6f4e985

Please sign in to comment.