GitHub Primer JS behaviour

Merge Box

The merge panel with Merge/Squash/Rebase options and the green Merge pull request button. The moment of truth of every PR, unmistakably GitHub.

Documentation

Real scenarios

The component as it is used in a product — not a specimen grid.

Green means go

Pick a method — the commit message rewrites itself the GitHub way. Then press the green button and watch the box settle into its purple, final verdict.

The three verdicts of the box

Clean arms the green button, conflicts mute it behind a fix-first link, and the merged state closes the story in done purple.

No conflicts with the base branch

Create a merge commit clean

This branch has conflicts that must be resolved

Squash and merge conflicts

Merged — 2 days ago

merged · done purple

Important props

Important props
Prop Type Default What it does
method radio 'merge' merge · squash · rebase; each rewrite rewrites the commit title and body.
status state 'clean' Clean: a green tick and an armed button; conflicts: red and a muted button.
action button 'success · 6px' The green Merge pull request button; after merging the whole box flips to the purple merged state.
commit message textarea 'PR title + body' The editable commit message with the PR number (#412) previewed.

Snippet

<div class="prm-box">
    <header class="prm-status">
        <svg>…</svg> This branch has no conflicts with the base branch
    </header>
    <label><input type="radio" name="prm-method" checked> Create a merge commit</label>
    <label><input type="radio" name="prm-method"> Squash and merge</label>
    <label><input type="radio" name="prm-method"> Rebase and merge</label>
    <button class="prm-go">Merge pull request</button>
</div>

<style>
.prm-box { inline-size: min(100%, 30rem); padding: 16px; border: 1px solid #d1d9e0;
           border-radius: 6px; background: #f6f8fa; }
.prm-status { color: #1a7f37; font: 500 14px system-ui; }
.prm-go { block-size: 32px; padding-inline: 12px; border-radius: 6px; border: 0;
          background: #1f883d; color: #fff; font: 500 14px system-ui; }
</style>
// resources/js/Pages/Pulls/Merge.tsx — the green button PATCHes
// the pull request; Inertia swaps in the merged state afterwards.
import { Head, router } from '@inertiajs/react';
import MergeBox from '@/components/primer/MergeBox';

export default function PullMerge() {
  return (
    <>
      <Head title="Merge · PR #412" />
      {/* onMerge={(method) => router.patch('/pulls/412', { method })} */}
      <MergeBox />
    </>
  );
}
import { useState } from 'react';
import '@nabuxai/ui-core/css';

type Method = 'merge' | 'squash' | 'rebase';
const GO: Record<Method, string> = {
  merge: 'Merge pull request',
  squash: 'Confirm squash and merge',
  rebase: 'Confirm rebase and merge',
};

export default function MergeBox() {
  const [method, setMethod] = useState<Method>('merge');
  const [merged, setMerged] = useState(false);

  return (
    <div className="prm-box" data-merged={merged || undefined}>
      {merged ? (
        <p className="prm-done"><b>Pull request successfully merged</b> — the branch is closed and deletable.</p>
      ) : (
        <>
          <p className="prm-status" data-kind="clean">✓ This branch has no conflicts with the base branch</p>
          {(Object.keys(GO) as Method[]).map((m) => (
            <label key={m}>
              <input type="radio" name="prm-method" checked={method === m} onChange={() => setMethod(m)} /> {GO[m]}
            </label>
          ))}
          <button className="prm-go" onClick={() => setMerged(true)}>✓ {GO[method]}</button>
        </>
      )}
      <style>{`
        .prm-box { inline-size: min(100%, 30rem); padding: 16px; border: 1px solid #d1d9e0;
                   border-radius: 6px; background: #f6f8fa; display: grid; gap: 10px; }
        .prm-status { color: #1a7f37; font: 500 14px system-ui; margin: 0; }
        .prm-go { block-size: 32px; padding-inline: 12px; border-radius: 6px; border: 0; justify-self: start;
                  background: #1f883d; color: #fff; font: 500 14px system-ui; }
        .prm-box[data-merged] { border-color: #8250DF; background: #FBF8FF; }
      `}</style>
    </div>
  );
}
<!-- MergeBox.vue -->
<script setup lang="ts">
import { ref } from 'vue';
import '@nabuxai/ui-core/css';

type Method = 'merge' | 'squash' | 'rebase';
const GO: Record<Method, string> = {
  merge: 'Merge pull request',
  squash: 'Confirm squash and merge',
  rebase: 'Confirm rebase and merge',
};
const method = ref<Method>('merge');
const merged = ref(false);
</script>

<template>
  <div class="prm-box" :data-merged="merged ? '' : null">
    <template v-if="!merged">
      <p class="prm-status" data-kind="clean">✓ This branch has no conflicts with the base branch</p>
      <label v-for="(label, m) in GO" :key="m">
        <input v-model="method" type="radio" name="prm-method" :value="m" /> {{ label }}
      </label>
      <button class="prm-go" @click="merged = true">✓ {{ GO[method] }}</button>
    </template>
    <p v-else class="prm-done"><b>Pull request successfully merged</b> — the branch is closed and deletable.</p>
  </div>
</template>

<style scoped>
.prm-box { inline-size: min(100%, 30rem); padding: 16px; border: 1px solid #d1d9e0;
           border-radius: 6px; background: #f6f8fa; display: grid; gap: 10px; }
.prm-status { color: #1a7f37; font: 500 14px system-ui; margin: 0; }
.prm-go { block-size: 32px; padding-inline: 12px; border-radius: 6px; border: 0; justify-self: start;
          background: #1f883d; color: #fff; font: 500 14px system-ui; }
.prm-box[data-merged] { border-color: #8250df; background: #fbf8ff; }
</style>
<!-- MergeBox.svelte -->
<script lang="ts">
  import '@nabuxai/ui-core/css';

  type Method = 'merge' | 'squash' | 'rebase';
  const GO: Record<Method, string> = {
    merge: 'Merge pull request',
    squash: 'Confirm squash and merge',
    rebase: 'Confirm rebase and merge',
  };
  let method = $state<Method>('merge');
  let merged = $state(false);
</script>

<div class="prm-box" data-merged={merged || undefined}>
  {#if !merged}
    <p class="prm-status" data-kind="clean">✓ This branch has no conflicts with the base branch</p>
    {#each Object.keys(GO) as m (m)}
      <label>
        <input type="radio" name="prm-method" checked={method === m} onchange={() => (method = m as Method)} /> {GO[m as Method]}
      </label>
    {/each}
    <button class="prm-go" onclick={() => (merged = true)}>✓ {GO[method]}</button>
  {:else}
    <p class="prm-done"><b>Pull request successfully merged</b> — the branch is closed and deletable.</p>
  {/if}
</div>

<style>
.prm-box { inline-size: min(100%, 30rem); padding: 16px; border: 1px solid #d1d9e0;
           border-radius: 6px; background: #f6f8fa; display: grid; gap: 10px; }
.prm-status { color: #1a7f37; font: 500 14px system-ui; margin: 0; }
.prm-go { block-size: 32px; padding-inline: 12px; border-radius: 6px; border: 0; justify-self: start;
          background: #1f883d; color: #fff; font: 500 14px system-ui; }
.prm-box[data-merged] { border-color: #8250df; background: #fbf8ff; }
</style>